-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day6.py
59 lines (45 loc) · 1.42 KB
/
Day6.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
path = "./Inputs/day6.txt"
# path = "./Inputs/day6Test.txt"
def part1():
count = 0
anyoneYes = []
with open(path) as file:
for line in file.readlines():
line = line.rstrip('\n')
if line:
anyoneYes.extend(list(line))
else:
# end of group
count += len(set(anyoneYes)) # set only stores unique values
anyoneYes = []
# do last group
count += len(set(anyoneYes))
print("Part 1:")
print(count)
def part2():
count = 0
everyoneYes = []
startGroup = True
with open(path) as file:
for line in file.readlines():
line = line.rstrip('\n')
if line and startGroup == True:
# process first person in group
everyoneYes.extend(list(line))
startGroup = False
elif line:
# remove any from everyoneYes that weren't yes for next person
for p in set(everyoneYes) - set(list(line)):
everyoneYes.remove(p)
continue
else:
# end of group
count += len(set(everyoneYes))
everyoneYes = []
startGroup = True
# do last group
count += len(set(everyoneYes))
print("Part 2:")
print(count)
part1()
part2()