Second part of group questions
This commit is contained in:
parent
784e11a58b
commit
4d665d7c15
@ -10,16 +10,32 @@ def main() -> int:
|
||||
|
||||
|
||||
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:
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
yield len(cur_group)
|
||||
cur_group = set()
|
||||
for c in list(line):
|
||||
cur_group.add(c)
|
||||
yield cur_group
|
||||
cur_group = []
|
||||
continue
|
||||
|
||||
yield len(cur_group)
|
||||
cur_group.append(line)
|
||||
|
||||
yield cur_group
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -1 +1 @@
|
||||
counts_sum=11
|
||||
counts_sum=6
|
||||
|
@ -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")
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user