-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day3.py
37 lines (29 loc) · 770 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
32
33
34
35
36
37
from helpers.importHelpers import *
def getPriority(char):
if char.isupper():
return ord(char) - ord("A") + 27
else:
return ord(char) - ord("a") + 1
stringInput = getInput()
# Part 1:
resultPart1 = 0
for line in stringInput.split("\n"):
commonItem = ""
left, right = line[:len(line)//2], line[len(line)//2:]
for elem in left:
if elem in right:
commonItem = elem
break
resultPart1 += getPriority(commonItem)
#Part 2:
resultPart2 = 0
x = iter(stringInput.split("\n"))
for first, second, third in zip(x, x, x):
commonItem = ""
for elem in first:
if elem in second and elem in third:
commonItem = elem
break
resultPart2 += getPriority(commonItem)
print("Part 1: ", resultPart1)
print("Part 2: ", resultPart2)