]> git.friedersdorff.com Git - max/aoc_2022.git/blob - 3_2.py
Do day 7
[max/aoc_2022.git] / 3_2.py
1 from string import ascii_letters
2
3 sum_of_priorities = 0
4
5 def get_3_rucksacks(fh):
6     return [next(fh).strip() for _ in range(3)]
7
8
9 with open("3.in") as fh:
10     while True:
11         try:
12             rucksacks = get_3_rucksacks(fh)
13         except StopIteration:
14             break
15
16         a, b, c = rucksacks
17
18         item_in_all = list(set(a).intersection(set(b)).intersection(set(c)))[0]
19
20         priority = ascii_letters.find(item_in_all) + 1
21         sum_of_priorities += priority
22
23 print(sum_of_priorities)