Skip to content

Commit 05cc133

Browse files
Advent of Code 2025 - Day 1 : Python version (#47)
* add solution for 2025 * rm pyc file
1 parent f368626 commit 05cc133

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

advent_of_code/2025(python)/__init__.py

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
def solve_day1_part1(actions):
3+
start_degree = 50
4+
res = 0
5+
6+
for ac in actions:
7+
step = (int(ac[1:])) % 100
8+
match ac[0]:
9+
case 'L':
10+
start_degree -= step
11+
if start_degree < 0:
12+
start_degree = 100 + start_degree
13+
case 'R':
14+
start_degree += step
15+
if start_degree >= 100:
16+
start_degree = start_degree-100
17+
18+
res += 1 if start_degree == 0 else 0
19+
20+
return res
21+
22+
23+
def solve_day1_part2(actions):
24+
start_degree = 50
25+
res = 0
26+
27+
for ac in actions:
28+
step = (int(ac[1:]))
29+
res += step//100
30+
31+
step = step % 100
32+
start_degree = start_degree % 100
33+
if step == 0:
34+
continue
35+
36+
initial_start = start_degree
37+
match ac[0]:
38+
case 'L':
39+
start_degree -= step
40+
if start_degree <= 0:
41+
start_degree = 100 + start_degree
42+
if initial_start != 0 and start_degree != 0:
43+
res += 1
44+
case 'R':
45+
start_degree += step
46+
if start_degree >= 100:
47+
start_degree = start_degree-100
48+
if initial_start != 0 and start_degree != 0:
49+
res += 1
50+
res += 1 if start_degree == 0 else 0
51+
52+
return res
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import unittest
2+
3+
from day1 import solve_day1_part1, solve_day1_part2
4+
5+
question_input = [
6+
"L68",
7+
"L30",
8+
"R48",
9+
"L5",
10+
"R60",
11+
"L55",
12+
"L1",
13+
"L99",
14+
"R14",
15+
"L82",
16+
]
17+
18+
19+
class TestSample(unittest.TestCase):
20+
21+
def test_part1(self):
22+
self.assertEqual(solve_day1_part1(question_input), 3)
23+
24+
def test_part2(self):
25+
self.assertEqual(solve_day1_part2(question_input), 6)
26+
27+
28+
if __name__ == "__main__":
29+
unittest.main()

run-ci.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ done
2020
# For solutions with Python
2121
# may need to use another list for python folders next year
2222
echo "==entering Python solution folder=="
23-
cd "2024(python)"
24-
python -m unittest discover
23+
cd "2024(python)" && python -m unittest discover && cd .. && cd "2025(python)" && python -m unittest discover

0 commit comments

Comments
 (0)