Group questions first part

This commit is contained in:
Dan Buch 2021-01-10 21:04:31 -05:00
parent 9b90743cc1
commit 784e11a58b
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7
5 changed files with 66 additions and 3 deletions

View File

@ -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
View 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
View File

@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b

View File

@ -0,0 +1 @@
counts_sum=11

View 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")
]