Group questions first part

cat-town
Dan Buch 3 years ago
parent 9b90743cc1
commit 784e11a58b
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -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=")
]

@ -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())

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

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

@ -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…
Cancel
Save