# https://adventofcode.com/2024/day/1#part2 # Calculate a similarity score by multiplying each value in list 1 # by the number of times it appears in list 2. If a value in list 1 # doesn't appear in list 2, it contributes 0 to the similarity score. FILENAME = "input01.txt" def main(): with open(FILENAME, "r") as file: lines = [line.strip().split() for line in file.readlines()] first_list, second_list = [], [] for line in lines: first_list.append(int(line[0])) second_list.append(int(line[1])) similarity = 0 for i, el in enumerate(first_list): el_num = second_list.count(el) el_sim = el * el_num similarity += el_sim if i%5 == 0: print(f"Current location {el}, which appears {el_num} times in list 2, current similarity {el_sim}, accumulated similarity {similarity}.") print(f"Total accumulated similarity: {similarity}") return similarity if __name__ == "__main__": main()