2022 - Day 3 part 2

This commit is contained in:
kleph 2022-12-03 10:06:56 +01:00
parent 451fe9e6bf
commit 87a8ee1022

32
2022/3/3_2.py Normal file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
# 2022 - Advent Of Code 3 - part2
# file = 'input_example.txt'
file = 'input.txt'
prio = 0
def find_common(b1, b2, b3):
common1 = set(b1).intersection(b2)
common2 = set(b1).intersection(b3)
common_all = common1.intersection(common2)
print(f"c1: {common1} c2: {common2} -> {common_all}")
return list(common_all)
def convert_score(lnum):
num = ord(lnum[0])
if num > 90: # lower case
return num - 96
return num - 64 + 26
with open(file, encoding="utf-8") as f:
while line := f.readline():
bag1 = line
bag2 = f.readline().strip()
bag3 = f.readline().strip()
prio += convert_score(find_common(bag1, bag2, bag3))
print(prio)