adventofcode2024/day01/sol.py

19 lines
355 B
Python
Raw Normal View History

2024-12-02 03:40:57 +00:00
#input = open("sample1.in")
input = open("input")
nums = [[int(x) for x in line.split()] for line in input]
# part 1
a = [x[0] for x in nums]
b = [x[1] for x in nums]
a.sort()
b.sort()
distance = [abs(x-y) for x,y in zip(a,b)]
print(sum(distance))
# part 2
from collections import Counter
c = Counter(b)
scores = [x*c[x] for x in a]
print(sum(scores))