Skip to content

Commit 1455dc9

Browse files
Finish 2025 day1
1 parent f51ab66 commit 1455dc9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

2025/src/day1.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from math import floor
2+
from common import *
3+
4+
DAY_NUMBER = 1
5+
6+
with get_data(DAY_NUMBER) as f:
7+
instructions = [int(i) for i in [lines.strip().replace('R', '').replace('L', '-') for lines in f.readlines()]]
8+
9+
# Part 1
10+
dial = 50
11+
result = 0
12+
13+
for i in instructions:
14+
dial += i
15+
dial %= 100
16+
17+
if dial == 0:
18+
result += 1
19+
20+
print_result(DAY_NUMBER, 1, result)
21+
22+
# Part 2
23+
dial = 50
24+
result = 0
25+
26+
for i in instructions:
27+
was_zero = dial == 0
28+
29+
dial += i
30+
result += floor(abs(dial) / 100)
31+
result += 1 if ((dial < 0 or dial == 0) and not was_zero) else 0
32+
33+
dial %= 100
34+
35+
print_result(DAY_NUMBER, 2, result)
36+

0 commit comments

Comments
 (0)