44 lines
964 B
Python
44 lines
964 B
Python
|
#! /usr/bin/env python3
|
||
|
|
||
|
|
||
|
def iter_groups():
|
||
|
group_responses = []
|
||
|
with open("input.txt") as f:
|
||
|
for line in f:
|
||
|
line = line.strip()
|
||
|
if line == "":
|
||
|
# Group divider
|
||
|
yield group_responses
|
||
|
group_responses = []
|
||
|
else:
|
||
|
group_responses.append(line)
|
||
|
else:
|
||
|
if group_responses:
|
||
|
yield group_responses
|
||
|
|
||
|
|
||
|
def part1():
|
||
|
total = 0
|
||
|
for group in iter_groups():
|
||
|
questions = set()
|
||
|
for person in group:
|
||
|
for question in person:
|
||
|
questions.add(question)
|
||
|
total += len(questions)
|
||
|
print("Total", total)
|
||
|
|
||
|
|
||
|
def part2():
|
||
|
total = 0
|
||
|
for group in iter_groups():
|
||
|
result = set(group[0])
|
||
|
for person in group[1:]:
|
||
|
result = result & set(person)
|
||
|
total += len(result)
|
||
|
print("Total", total)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
part1()
|
||
|
part2()
|