2022 day 3
This commit is contained in:
26
2022/03/part2
Executable file
26
2022/03/part2
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
import itertools
|
||||
|
||||
VALS = {}
|
||||
|
||||
for i in range(ord('a'), ord('z')+1):
|
||||
VALS[chr(i)] = i - ord('a') + 1
|
||||
|
||||
for i in range(ord('A'), ord('Z')+1):
|
||||
VALS[chr(i)] = i - ord('A') + 27
|
||||
|
||||
score = 0
|
||||
|
||||
with open('input') as f:
|
||||
for elfA,elfB,elfC in itertools.zip_longest(*[f]*3):
|
||||
elfA = elfA.rstrip()
|
||||
elfB = elfB.rstrip()
|
||||
elfC = elfC.rstrip()
|
||||
|
||||
common = set(elfA) & set(elfB) & set(elfC)
|
||||
|
||||
score = score + VALS[common.pop()]
|
||||
|
||||
print(score)
|
||||
|
||||
|
Reference in New Issue
Block a user