From f7e6dd05df4d8aa7936e067a0261ac3572c8ad76 Mon Sep 17 00:00:00 2001 From: germax26 Date: Sun, 1 Dec 2024 21:10:07 +1100 Subject: [PATCH] 2024 Day 01 --- 2024/day01/day01.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2024/day01/day01.py 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