Add 2024/day1/part1.py
This commit is contained in:
parent
df6b1a9b42
commit
f97b157d72
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
list1 = [];
|
||||||
|
list2 = [];
|
||||||
|
with open("input.txt") as file:
|
||||||
|
for line in file:
|
||||||
|
if line.strip():
|
||||||
|
num1,num2 = map(int, line.split())
|
||||||
|
list1.append(num1)
|
||||||
|
list2.append(num2)
|
||||||
|
|
||||||
|
slist1 = sorted(list1);
|
||||||
|
slist2 = sorted(list2);
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
for index in range(len(slist1)):
|
||||||
|
result+=abs(slist1[index]-slist2[index])
|
||||||
|
|
||||||
|
print(f'Result: {result}')
|
Loading…
Reference in New Issue