2024 Day 01
This commit is contained in:
parent
30e4e6049b
commit
f7e6dd05df
16
2024/day01/day01.py
Normal file
16
2024/day01/day01.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
with open('input.txt', 'r') as f:
|
||||||
|
lines = [tuple(map(int, line.strip().split())) for line in f.readlines()]
|
||||||
|
|
||||||
|
list1 = [line[0] for line in lines]
|
||||||
|
list2 = [line[1] for line in lines]
|
||||||
|
list1.sort()
|
||||||
|
list2.sort()
|
||||||
|
|
||||||
|
differences = [abs(a-b) for a, b in zip(list1, list2)]
|
||||||
|
print(f'Part 1: {sum(differences)}')
|
||||||
|
|
||||||
|
counts = Counter(list2)
|
||||||
|
scores = [x * counts.get(x, 0) for x in list1]
|
||||||
|
print(f'Part 2: {sum(scores)}')
|
Loading…
Reference in New Issue
Block a user