2024 day 1.

This commit is contained in:
Mikaël Capelle
2024-12-01 10:26:02 +01:00
parent def4305c1c
commit 4dd2d5d9c9
78 changed files with 1261 additions and 13 deletions

View 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}")