-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06.py
More file actions
33 lines (29 loc) · 863 Bytes
/
06.py
File metadata and controls
33 lines (29 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
with open("inputs/06.txt","r") as f:
data = f.read().splitlines()
# finding all questions answered "yes" to is the combined
# set of all the answers for that group.
def sumyes(data):
matching = 0
grouping = set()
for i in data:
if i == "":
matching += len(grouping)
grouping = set()
else:
grouping.update(i)
return matching + len(grouping)
# questions everyone answered "yes" to is the intersection of all the
# answers from that group. (using a..z to get complete first answer)
def sumallyes(data):
matching = 0
grouping = set('abcdefghijklmnopqrstuvwxyz')
for i in data:
if i == "":
matching += len(grouping)
grouping = set('abcdefghijklmnopqrstuvwxyz')
else:
grouping.intersection_update(i)
return matching + len(grouping)
print("Day 6")
print(" Part 1:", sumyes(data)) #6170
print(" Part 2:", sumallyes(data)) #2947