aoc-2024/1/1.py

13 lines
436 B
Python
Raw Normal View History

2024-12-03 08:39:30 +00:00
def distances(left: list[int], right: list[int]) -> list[int]:
left, right = sorted(left), sorted(right)
return [abs(l-r) for l, r in zip(left, right)]
if __name__ == '__main__':
with open('1.input') as file:
left, right = [], []
for line in file:
l, r = line.split()
l, r = int(l), int(r)
left.append(l)
right.append(r)
print(sum(distances(left, right)))