01_solution.py 485 B

123456789101112131415
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Sun Dec 1 11:41:41 2024
  5. @author: bernie
  6. """
  7. with open("01_input.txt", "r") as inpt_file:
  8. inpt = [line.split(" ") for line in inpt_file.readlines()]
  9. left_list = sorted(int(line[0]) for line in inpt)
  10. right_list = sorted(int(line[1]) for line in inpt)
  11. print(f"part 1: {sum(abs(left-right) for left, right in zip(left_list, right_list))}")
  12. print(f"part 2: {sum(left * right_list.count(left) for left in left_list)}")