-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.py
More file actions
executable file
·42 lines (28 loc) · 717 Bytes
/
day1.py
File metadata and controls
executable file
·42 lines (28 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from collections import Counter
from aoc_utils import * # type: ignore
from aocd import get_data
data = get_data(year=2024, day=1, block=True)
def part_one(data):
aa, bb = [], []
for line in data.splitlines():
a, b = ints(line)
aa.append(a)
bb.append(b)
aa, bb = sorted(aa), sorted(bb)
distance = 0
for a, b in zip(aa, bb):
distance += abs(a - b)
return distance
def part_two(data):
aa, bb = [], []
for line in data.splitlines():
a, b = ints(line)
aa.append(a)
bb.append(b)
cb = Counter(bb)
score = 0
for a in aa:
score += a * cb[a]
return score
print(part_one(data))
print(part_two(data))