-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.py
83 lines (70 loc) · 2.29 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sys
#any
def get_group_lists(input):
#grouplist = []
groupset = set()
fulllist = []
for i,line in enumerate(input):
if not line == '':
#print(line)
#grouplist.append(line)
for char in list(line):
groupset.add(char)
elif line == '':
fulllist.append(list(groupset))
groupset = set()
if i == len(input)-1:
fulllist.append(list(groupset))
return fulllist
#all
def get_group_lists2(input):
grouplist = []
#groupset = set()
fulllist = []
groupline = 0
for i,line in enumerate(input):
if not line == '':
#print(line)
#grouplist.append(line)
for char in list(line):
#groupset.add(char)
grouplist.append(char)
groupline = groupline + 1
elif line == '':
#fulllist.append(list(groupset))
#print(groupline)
#print(grouplist)
newgrouplist = set()
for answer in grouplist:
for char in answer:
if grouplist.count(char) == groupline :
newgrouplist.add(char)
break
fulllist.append(list(newgrouplist))
#groupset = set()
grouplist = []
groupline = 0
if i == len(input)-1:
newgrouplist = set()
for answer in grouplist:
for char in answer:
if grouplist.count(char) == groupline :
newgrouplist.add(char)
break
#fulllist.append(list(groupset))
fulllist.append(list(newgrouplist))
return fulllist
if __name__ == "__main__":
inputtxt = sys.argv[1]
with open(inputtxt,'r') as inp:
input = inp.readlines()
input_wo_newline = [line.strip() for line in input]
#Part 1
fulllist = get_group_lists(input_wo_newline)
flattenedlist = [item for sublist in fulllist for item in sublist]
print(len(flattenedlist))
#Part 2
thelist = get_group_lists2(input_wo_newline)
#print(thelist)
theflattenedlist = [item for sublist in thelist for item in sublist]
print(len(theflattenedlist))