aoc2024/day01.py

25 lines
403 B
Python
Raw Normal View History

2024-12-01 17:53:33 +00:00
#!/usr/bin/env python3
from collections import Counter
from functools import reduce
# 1
with open("day01") as f:
lines = f.readlines()
els = [l.split() for l in lines]
l1 = [int(el[0]) for el in els]
l2 = [int(el[1]) for el in els]
l1.sort()
l2.sort()
d = [abs(e[0] - e[1]) for e in zip(l1, l2)]
res = sum(d)
# 2
ctn = Counter(l2)
res = reduce(lambda accum, e: accum + e*ctn.get(e, 0), l1, 0)