Second part of group questions

This commit is contained in:
Dan Buch 2021-01-11 09:19:36 -05:00
parent 784e11a58b
commit 4d665d7c15
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7
3 changed files with 24 additions and 10 deletions

View File

@ -10,16 +10,32 @@ def main() -> int:
def _iter_group_counts(instream: typing.TextIO) -> typing.Generator[int, None, None]: def _iter_group_counts(instream: typing.TextIO) -> typing.Generator[int, None, None]:
cur_group = set() for i, group in enumerate(_iter_groups(instream)):
answers = set(list(group[0]))
print(f"i={i} initial={answers}")
for answers_text in group[1:]:
to_add = set(list(answers_text))
answers = answers.intersection(set(list(answers_text)))
print(f"i={i} added={to_add} result={answers}")
print(f"i={i} final={answers} n={len(answers)}")
yield len(answers)
def _iter_groups(instream):
cur_group = []
for line in instream: for line in instream:
line = line.strip() line = line.strip()
if line == "": if line == "":
yield len(cur_group) yield cur_group
cur_group = set() cur_group = []
for c in list(line): continue
cur_group.add(c)
yield len(cur_group) cur_group.append(line)
yield cur_group
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1 +1 @@
counts_sum=11 counts_sum=6

View File

@ -17,7 +17,5 @@ def test_solution(capsys):
expected_output = (HERE / "test-output").read_text().splitlines() expected_output = (HERE / "test-output").read_text().splitlines()
assert expected_output == [ assert expected_output == [
l l for l in capsys.readouterr().out.splitlines() if l.startswith("counts_sum")
for l in capsys.readouterr().out.splitlines()
if not l.startswith("highest_seat")
] ]