Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
52 changes: 52 additions & 0 deletions advent_of_code/2025(python)/day1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

def solve_day1_part1(actions):
start_degree = 50
res = 0

for ac in actions:
step = (int(ac[1:])) % 100
match ac[0]:
case 'L':
start_degree -= step
if start_degree < 0:
start_degree = 100 + start_degree
case 'R':
start_degree += step
if start_degree >= 100:
start_degree = start_degree-100

res += 1 if start_degree == 0 else 0

return res


def solve_day1_part2(actions):
start_degree = 50
res = 0

for ac in actions:
step = (int(ac[1:]))
res += step//100

step = step % 100
start_degree = start_degree % 100
if step == 0:
continue

initial_start = start_degree
match ac[0]:
case 'L':
start_degree -= step
if start_degree <= 0:
start_degree = 100 + start_degree
if initial_start != 0 and start_degree != 0:
res += 1
case 'R':
start_degree += step
if start_degree >= 100:
start_degree = start_degree-100
if initial_start != 0 and start_degree != 0:
res += 1
res += 1 if start_degree == 0 else 0

return res
29 changes: 29 additions & 0 deletions advent_of_code/2025(python)/test_day1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import unittest

from day1 import solve_day1_part1, solve_day1_part2

question_input = [
"L68",
"L30",
"R48",
"L5",
"R60",
"L55",
"L1",
"L99",
"R14",
"L82",
]


class TestSample(unittest.TestCase):

def test_part1(self):
self.assertEqual(solve_day1_part1(question_input), 3)

def test_part2(self):
self.assertEqual(solve_day1_part2(question_input), 6)


if __name__ == "__main__":
unittest.main()
3 changes: 1 addition & 2 deletions run-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ done
# For solutions with Python
# may need to use another list for python folders next year
echo "==entering Python solution folder=="
cd "2024(python)"
python -m unittest discover
cd "2024(python)" && python -m unittest discover && cd .. && cd "2025(python)" && python -m unittest discover
Loading