Files
aoc/03/c.py
2022-12-03 10:59:47 +02:00

30 lines
655 B
Python

import os
f = open(os.path.dirname(__file__)+"/input.txt", "r")
tot = 0
tot2 = 0
priorities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
rucksacks = f.read().splitlines()
f.close()
for data in rucksacks:
left = data[:len(data)//2]
right = data[len(data)//2:]
common = ''.join(set(left) & set(right))
tot += priorities.rfind(common)+1
print("First answer: " + str(tot))
start = 0
end = len(rucksacks)
step = 3
for i in range(start, end, step):
three = rucksacks[i:i+step]
common = ''.join(set(three[0]) & set(three[1]) & set(three[2]))
tot2 += priorities.rfind(common)+1
print("Second answer: " + str(tot2))