add: 2024/day01/part2

This commit is contained in:
Starnakin 2024-12-01 21:04:06 +01:00
parent cc708b5b97
commit 91f1535c73

18
2024/day01/part2.py Normal file
View File

@ -0,0 +1,18 @@
text: str
with open("test.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, [x * right.count(x) for x in left])))