[Advent of Code 2024](https://adventofcode.com/2024)
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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