adventofcode/2024/01/01.py

22 lines
462 B
Python
Raw Permalink Normal View History

2024-12-01 12:51:05 +01:00
#!/usr/bin/env python3
INPUT_FILE = 'input.txt'
def main():
left, right = [], []
contents = open(INPUT_FILE, 'r').readlines()
for line in contents:
fields = line.split(' ')
left.append(int(fields[0]))
right.append(int(fields[-1]))
left.sort()
right.sort()
diff_sum = 0
for pair in list(zip(left, right)):
diff_sum += abs(pair[0] - pair[1])
print(diff_sum)
if __name__ == '__main__':
main()