-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd6-code.py
More file actions
41 lines (34 loc) · 1.01 KB
/
d6-code.py
File metadata and controls
41 lines (34 loc) · 1.01 KB
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
with open("day6-input.txt", "r") as fp:
lines=fp.readlines()
groups = []
group = []
for question in lines:
if question!="\n":
group.append(question.split("\n")[0])
else:
groups.append(group)
group=[]
groups.append(group)
# solution to challenge 1
solution_1 = []
for group in groups:
#print(f"Group: ", group)
unique_ques = []
for ques in group:
unique_ques.extend([uq for uq in ques])
#print(f"Unique questions: {set(unique_ques)}")
solution_1.extend(list(set(unique_ques)))
print(f"Solution 1: {len(solution_1)}")
# solution to challenge 2
from collections import Counter
total = 0
for group in groups:
#print(f"\nGroup: {group}")
group_size = len(group)
#print(f"Length of group: {group_size}")
# make single list of enitire group and count occurence
counts = Counter("".join(group))
#print(counts)
counts = Counter(list(counts.values()))[group_size]
total+=counts
print(f"Solution 2:", total)