aoc24/day1/solution.py
2024-12-03 08:56:03 +01:00

34 lines
No EOL
490 B
Python

example = """
3 4
4 3
2 5
1 3
3 9
3 3
"""
parsed = [[],[]]
for x in open('input.txt', 'r').readlines():
if x:
a = [y for y in x.split(" ") if y]
parsed[0].append(a[0])
parsed[1].append(a[1])
parsed[0] = sorted(parsed[0])
parsed[1] = sorted(parsed[1])
asd = []
for x, y in zip(parsed[0], parsed[1]):
x = int(x)
y = int(y)
if x > y:
asd.append(x-y)
else:
asd.append(y-x)
num = sum(asd)
print(num)