]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blob - day06/get_yes_counts.py
Day 13 - forays in to using Diophantine did not go well.
[advent-of-code-2020.git] / day06 / get_yes_counts.py
1 #!/usr/bin/python
2
3 group_questions=[]
4 questions=dict()
5 people_count=0
6
7 for line in open("input.txt", "r"):
8     line=line.rstrip()
9     if (line == ""):
10         all_yes="".join(questions.keys())
11         everyone_yes="".join([a for a in questions.keys() if questions[a] == people_count])
12         group_questions.append((all_yes, everyone_yes))
13         questions=dict()
14         people_count=0
15         continue
16     people_count+=1
17     for char in line:
18         if char in questions:
19             questions[char]+=1
20         else:
21             questions[char]=1
22
23 if (len(questions.keys()) > 0):
24     all_yes="".join(questions.keys())
25     everyone_yes="".join([a for a in questions.keys() if questions[a] == people_count])
26     group_questions.append((all_yes, everyone_yes))
27
28 sum_of_groups=0
29 sum_of_everyone=0
30 for group in group_questions:
31     sum_of_groups+=len(group[0])
32     sum_of_everyone+=len(group[1])
33
34
35 print("Sum of groups: {}".format(sum_of_groups))
36 print("Sum of groups (everyone said yes): {}".format(sum_of_everyone))