advent_of_code/2022/3/3.py

22 lines
492 B
Python
Raw Normal View History

2022-12-03 09:28:15 +01:00
#!/usr/bin/env python
# 2022 - Advent Of Code 3
#file = 'input_example.txt'
file = 'input.txt'
prio = 0
with open(file, encoding="utf-8") as f:
for line in f.readlines():
half_len = int(len(line.strip()) / 2)
str1 = line[:half_len]
str2 = line[half_len:]
common = list(set(str1).intersection(str2))
num = ord(common[0])
if num > 90: # lower case
prio += num - 96
else:
prio += num - 64 + 26
print(prio)