-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3.py
31 lines (24 loc) · 809 Bytes
/
day3.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
#!/usr/bin/env python
f = open("ressources/day3.txt", "r")
lines = f.readlines()
score = 0
for line in lines:
sizeCompartment = len(line)
compartment1 = line[:sizeCompartment/2]
compartment2 = line[sizeCompartment/2:].strip()
commonItem = list(set(compartment1)&set(compartment2))[0]
if commonItem.isupper():
score += ord(commonItem)-64+26
else:
score += ord(commonItem)-96
print("Your Score is: {}".format(score))
score = 0
for line1, line2, line3 in zip(lines[0::3], lines[1::3], lines[2::3]):
commons = list(set(line1)&set(line2)&set(line3))
commons.sort()
commonItem = commons[1]
if commonItem.isupper():
score += ord(commonItem)-64+26
else:
score += ord(commonItem)-96
print("Your Score is: {}".format(score))