2025 - Day 1 (Secret Entrance)

View puzzle description on AdventOfCode.com
Part 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3

#Advent of Code
#2025 Day 1, Part 1
#Solution by James C. (https://github.com/JamesMCo)

import os, sys
sys.path.append(os.path.abspath("../.."))
import unittest, util.read
from util.tests import run

def solve(puzzle_input: list[str]) -> int:
    pointing = 50
    count = 0

    for instruction in puzzle_input:
        rotation = int(instruction[1:]) * (1 if instruction[0] == "R" else -1)
        pointing = (pointing + rotation) % 100
        if pointing == 0:
            count += 1

    return count

def main() -> tuple[str, int]:
    puzzle_input = util.read.as_lines()

    return "The password to open the door is {}.", solve(puzzle_input)

class AOC_Tests(unittest.TestCase):
    def test_ex1(self):
        return self.assertEqual(solve(["L68",
                                       "L30",
                                       "R48",
                                       "L5",
                                       "R60",
                                       "L55",
                                       "L1",
                                       "L99",
                                       "R14",
                                       "L82"]), 3)

if __name__ == "__main__":
    run(main)
Part 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3

#Advent of Code
#2025 Day 1, Part 2
#Solution by James C. (https://github.com/JamesMCo)

import os, sys
sys.path.append(os.path.abspath("../.."))
import unittest, util.read
from util.tests import run

def solve(puzzle_input: list[str]) -> int:
    pointing = 50
    count = 0

    for instruction in puzzle_input:
        rotation = int(instruction[1:])
        if rotation >= 100:
            count += rotation // 100
            rotation %= 100
        rotation *= 1 if instruction[0] == "R" else -1

        if pointing == 0:
            # Only want to count clicks that enter the 0 state, not leave it
            pointing = (pointing + rotation) % 100
        else:
            pointing += rotation
            if rotation < 0 and pointing <= 0:
                count += 1
            elif rotation > 0 and pointing >= 100:
                count += 1
            pointing %= 100

    return count

def main() -> tuple[str, int]:
    puzzle_input = util.read.as_lines()

    return "The password to open the door is {}.", solve(puzzle_input)

class AOC_Tests(unittest.TestCase):
    def test_ex1(self):
        return self.assertEqual(solve(["L68",
                                       "L30",
                                       "R48",
                                       "L5",
                                       "R60",
                                       "L55",
                                       "L1",
                                       "L99",
                                       "R14",
                                       "L82"]), 6)

if __name__ == "__main__":
    run(main)
Return to solution index