aoc
/
2022
1
0
Fork 0
This commit is contained in:
Sijmen 2022-12-03 19:22:35 +01:00
parent e9b71955f9
commit 5c997bb158
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
2 changed files with 29 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.in
*.ex

28
day03.py Normal file
View File

@ -0,0 +1,28 @@
import fileinput
input = [s.strip() for s in fileinput.input()]
part1, part2 = 0, 0
def prio(x):
if x.islower():
return ord(x) - ord("a") + 1
else:
return ord(x) - ord("A") + 27
for line in input:
first = set(line[: len(line) // 2])
second = set(line[len(line) // 2 :])
both = (first & second).pop()
part1 += prio(both)
for i in range(0, len(input), 3):
x = set(input[i])
y = set(input[i + 1])
z = set(input[i + 2])
overlap = (x & y & z).pop()
part2 += prio(overlap)
print(part1, part2)