diff --git a/advent_of_code/2025(python)/__init__.py b/advent_of_code/2025(python)/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/advent_of_code/2025(python)/day1.py b/advent_of_code/2025(python)/day1.py new file mode 100644 index 0000000..c4b4b2b --- /dev/null +++ b/advent_of_code/2025(python)/day1.py @@ -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 diff --git a/advent_of_code/2025(python)/test_day1.py b/advent_of_code/2025(python)/test_day1.py new file mode 100644 index 0000000..a7f069b --- /dev/null +++ b/advent_of_code/2025(python)/test_day1.py @@ -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() diff --git a/run-ci.sh b/run-ci.sh index dfa7f9c..16a37f6 100644 --- a/run-ci.sh +++ b/run-ci.sh @@ -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 \ No newline at end of file +cd "2024(python)" && python -m unittest discover && cd .. && cd "2025(python)" && python -m unittest discover \ No newline at end of file