Group questions first part
This commit is contained in:
parent
9b90743cc1
commit
784e11a58b
@ -17,7 +17,5 @@ def test_solution(capsys):
|
||||
|
||||
expected_output = (HERE / "test-output").read_text().splitlines()
|
||||
assert expected_output == [
|
||||
l
|
||||
for l in capsys.readouterr().out.splitlines()
|
||||
if not l.startswith("highest_seat")
|
||||
l for l in capsys.readouterr().out.splitlines() if l.startswith("counts_sum=")
|
||||
]
|
||||
|
26
aoc2020/day06/solution.py
Normal file
26
aoc2020/day06/solution.py
Normal file
@ -0,0 +1,26 @@
|
||||
import sys
|
||||
import typing
|
||||
|
||||
|
||||
def main() -> int:
|
||||
counts_sum = sum([c for c in _iter_group_counts(sys.stdin)])
|
||||
print(f"counts_sum={counts_sum}")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def _iter_group_counts(instream: typing.TextIO) -> typing.Generator[int, None, None]:
|
||||
cur_group = set()
|
||||
for line in instream:
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
yield len(cur_group)
|
||||
cur_group = set()
|
||||
for c in list(line):
|
||||
cur_group.add(c)
|
||||
|
||||
yield len(cur_group)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
15
aoc2020/day06/test-input
Normal file
15
aoc2020/day06/test-input
Normal file
@ -0,0 +1,15 @@
|
||||
abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b
|
1
aoc2020/day06/test-output
Normal file
1
aoc2020/day06/test-output
Normal file
@ -0,0 +1 @@
|
||||
counts_sum=11
|
23
aoc2020/day06/test_solution.py
Normal file
23
aoc2020/day06/test_solution.py
Normal file
@ -0,0 +1,23 @@
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from solution import main
|
||||
|
||||
|
||||
HERE = Path(__file__).absolute().parent
|
||||
|
||||
|
||||
def test_solution(capsys):
|
||||
with (HERE / "test-input").open() as infile:
|
||||
sys.stdin = infile
|
||||
main()
|
||||
|
||||
expected_output = (HERE / "test-output").read_text().splitlines()
|
||||
assert expected_output == [
|
||||
l
|
||||
for l in capsys.readouterr().out.splitlines()
|
||||
if not l.startswith("highest_seat")
|
||||
]
|
Loading…
Reference in New Issue
Block a user