2024 day 1.
This commit is contained in:
14
src/holt59/aoc/2024/day1.py
Normal file
14
src/holt59/aoc/2024/day1.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import sys
|
||||
from collections import Counter
|
||||
|
||||
values = list(map(int, sys.stdin.read().strip().split()))
|
||||
|
||||
column_1 = sorted(values[::2])
|
||||
column_2 = sorted(values[1::2])
|
||||
counter_2 = Counter(column_2)
|
||||
|
||||
answer_1 = sum(abs(v1 - v2) for v1, v2 in zip(column_1, column_2, strict=True))
|
||||
answer_2 = sum(value * counter_2.get(value, 0) for value in column_1)
|
||||
|
||||
print(f"answer 1 is {answer_1}")
|
||||
print(f"answer 2 is {answer_2}")
|
Reference in New Issue
Block a user