File tree Expand file tree Collapse file tree 4 files changed +82
-2
lines changed
advent_of_code/2025(python) Expand file tree Collapse file tree 4 files changed +82
-2
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 2020# For solutions with Python
2121# may need to use another list for python folders next year
2222echo " ==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
You can’t perform that action at this time.
0 commit comments