AdventOfCode/2024/day1.py

22 lines
444 B
Python
Raw Normal View History

2024-12-01 11:10:12 +01:00
from collections import Counter
total = 0
left = []
right = []
with open("input1.txt") as f:
for line in f:
line = line.rstrip().split()
left.append(int(line[0]))
right.append(int(line[-1]))
left.sort()
right.sort()
for vl, vr in zip(left, right):
total += max(vl, vr) - min(vl, vr)
print("Total:", total)
total = 0
counter = Counter(right)
for vl in left:
total += vl * counter[vl]
print("Total:", total)