advent_of_code/2022/3/3.py
kleph 451fe9e6bf
All checks were successful
continuous-integration/drone/push Build is passing
2022 - Day 3 part 1
2022-12-03 09:28:15 +01:00

21 lines
492 B
Python

#!/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)