#!/usr/bin/env python # 2022 - Advent Of Code 3 - part1 # 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)