add: 2024/day01/part1
This commit is contained in:
parent
5377ef9abe
commit
cc708b5b97
18
2024/day01/part1.py
Normal file
18
2024/day01/part1.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
text: str
|
||||||
|
|
||||||
|
with open("input.txt") as f:
|
||||||
|
text = f.read()
|
||||||
|
|
||||||
|
lines: list[str] = text.splitlines()
|
||||||
|
data: list[list[str]] = [line.split(" ") for line in lines]
|
||||||
|
|
||||||
|
right_data: list[str] = [tmp[1] for tmp in data]
|
||||||
|
left_data: list[str] = [tmp[0] for tmp in data]
|
||||||
|
|
||||||
|
right: list[int] = list(map(int, right_data))
|
||||||
|
left: list[int] = list(map(int, left_data))
|
||||||
|
|
||||||
|
right.sort()
|
||||||
|
left.sort()
|
||||||
|
|
||||||
|
print(sum(map(abs, [a_i - b_i for a_i, b_i in zip(left, right)])))
|
Loading…
Reference in New Issue
Block a user