2024 - Day 1 part 1
This commit is contained in:
parent
fbf912a730
commit
05e956b7ae
3 changed files with 1028 additions and 0 deletions
22
2024/1/1.py
Normal file
22
2024/1/1.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
# 2024 - Advent Of Code 1
|
||||
|
||||
# file = 'input_example.txt'
|
||||
file = 'input.txt'
|
||||
|
||||
firsts = []
|
||||
seconds = []
|
||||
accum = 0
|
||||
with open(file, encoding="utf-8") as f:
|
||||
for line in f.readlines():
|
||||
a, b, c, d = line.strip().split(' ')
|
||||
firsts.append(int(a))
|
||||
seconds.append(int(d))
|
||||
|
||||
firsts.sort()
|
||||
seconds.sort()
|
||||
|
||||
for x, y in zip(firsts, seconds):
|
||||
accum += abs(y - x)
|
||||
|
||||
print(f"sum: {accum}")
|
1000
2024/1/input.txt
Normal file
1000
2024/1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
6
2024/1/input_example.txt
Normal file
6
2024/1/input_example.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
Loading…
Reference in a new issue