-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday03.py
33 lines (25 loc) · 859 Bytes
/
day03.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
import string
priority = string.ascii_lowercase + string.ascii_uppercase
def common(x,y):
for letter in x:
if (y.find(letter) != -1):
return letter
def three_common(x,y,z):
for letterX in x:
if (y.find(letterX) != -1):
if (z.find(letterX) != -1):
return letterX
sum = 0
with open('day03.txt') as f:
lines = f.readlines()
for i in range(0, len(lines)-2, 3):
#first = line[0:len(line)//2]
#second = line[len(line)//2: len(line)]
first = lines[i].strip()
second = lines[i+1].strip()
third = lines[i+2].strip()
bag = three_common(first,second, third)
p = priority.index(bag) + 1
sum += p
print(first, " ", second, " common letter: ", bag, "priority: ", p)
print(sum)