43 lines
990 B
Python
43 lines
990 B
Python
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]:
|
|
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 cur_group
|
|
cur_group = []
|
|
continue
|
|
|
|
cur_group.append(line)
|
|
|
|
yield cur_group
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|