aoc
/
2022
1
0
Fork 0
2022/day03.py

33 lines
662 B
Python
Raw Permalink Normal View History

2022-12-03 18:22:35 +00:00
import fileinput
def prio(x):
if x.islower():
return ord(x) - ord("a") + 1
else:
return ord(x) - ord("A") + 27
2022-12-24 14:59:27 +00:00
def main():
input = [s.strip() for s in fileinput.input()]
part1, part2 = 0, 0
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)
2022-12-03 18:22:35 +00:00
2022-12-24 14:59:27 +00:00
print(part1, part2)
2022-12-03 18:22:35 +00:00
2022-12-24 14:59:27 +00:00
if __name__ == "__main__":
main()