diff --git a/2024/day01/day01.py b/2024/day01/day01.py new file mode 100644 index 0000000..8494525 --- /dev/null +++ b/2024/day01/day01.py @@ -0,0 +1,16 @@ +from collections import Counter + +with open('input.txt', 'r') as f: + lines = [tuple(map(int, line.strip().split())) for line in f.readlines()] + +list1 = [line[0] for line in lines] +list2 = [line[1] for line in lines] +list1.sort() +list2.sort() + +differences = [abs(a-b) for a, b in zip(list1, list2)] +print(f'Part 1: {sum(differences)}') + +counts = Counter(list2) +scores = [x * counts.get(x, 0) for x in list1] +print(f'Part 2: {sum(scores)}') \ No newline at end of file