-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_2.py
59 lines (42 loc) · 1.16 KB
/
day_2.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
with open('files/day_2_input.txt') as f:
ids = [ id.strip() for id in f]
total_3 = 0
total_2 = 0
for i in ids:
counts = {}
for x in i:
if( x in counts.keys() ):
counts[x] += 1
else:
counts[x] = 1
check_3 = False
check_2 = False
for i in counts:
if(counts[i] == 3 and not check_3):
check_3 = True
elif(counts[i] == 2 and not check_2):
check_2 = True
if(check_3):
total_3 += 1
if(check_2):
total_2 += 1
print('Part 1: ' + str(total_2*total_3))
#Part 2
id_length = len(ids[0])
for i in range(len(ids)):
for j in range(i+1,len(ids)):
num_different = 0
for z in range(id_length):
if( ids[i][z]!=ids[j][z] ):
num_different += 1
if(num_different > 1):
break
if(num_different == 1):
final_answer = ''
for z in range(id_length):
if( ids[i][z]!=ids[j][z] ):
continue
else:
final_answer += ids[i][z]
print('Part 2: ' + str(final_answer))
exit()