-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.py
More file actions
65 lines (48 loc) · 1.29 KB
/
day1.py
File metadata and controls
65 lines (48 loc) · 1.29 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Advent of Code 2025, Day 1
# (c) blu3r4y
from aocd.models import Puzzle
from funcy import print_calls, print_durations
@print_calls
@print_durations(unit="ms")
def part1(sequence):
dial = 50
hits_zero = 0
for turn, steps in sequence:
if turn == "L":
dial -= steps
elif turn == "R":
dial += steps
dial %= 100
if dial == 0:
hits_zero += 1
return hits_zero
@print_calls
@print_durations(unit="ms")
def part2(sequence):
dial = 50
cross_zero = 0
for turn, steps in sequence:
if turn == "L":
if dial == 0: # adjust special case
cross_zero -= 1
dial -= steps
cross_zero += -((dial - 1) // 100)
elif turn == "R":
dial += steps
cross_zero += dial // 100
dial %= 100
return cross_zero
def load(data):
sequence = []
for line in data.splitlines():
turn, step = line[0], int(line[1:])
sequence.append((turn, step))
return sequence
if __name__ == "__main__":
puzzle = Puzzle(year=2025, day=1)
ans1 = part1(load(puzzle.input_data))
assert ans1 == 1059
puzzle.answer_a = ans1
ans2 = part2(load(puzzle.input_data))
assert ans2 == 6305
puzzle.answer_b = ans2