Yordi - A Lifelong Journey of Growth

Advent of Code 2025 - Day 1

Ladies and gentlemen, we are here! Advent of Code 2025 has begun! Let's take a look at day 1.

Check out my full solution for day 1 at GitHub.

Today's problem features a safe, protected by a dial with numbers from 0 to 99. At the start, the dial points at number 50. We are given a list of instructions, where each instruction tells us if we need to rotate the dial left (towards a lower number) or right (towards a higher number) and it also tells how many clicks we need to rotate. For example, the instruction 'L42' means we need to rotate left towards a lower number 42 times. As we are dealing with a rotating dial, whenever we reach the number 0 when rotating left, we continue at number 99. The same is true in the other direction: whenever we reach the number 99 when rotating right, we continue at number 0.

Part One

For part one of the puzzle, we need to count how many times the dial points exactly at number 0 after one instruction.

To begin, I initialize the variables pointer and zero_pointer at their respective starting values:

pointer = 50
zero_pointer = 0

Then, we need to go over each line of the input and parse each line as we read it. The first character is always an 'L' or an 'R' and the remaining characters are the number of clicks we need to rotate. We can save both in a variable:

direction = line[0]
clicks = int(line[1:])

Now we know the direction we need to rotate in and how many clicks we need to rotate, we can actually begin the rotation process. I've created a new function that accepts the current pointer, the direction to rotate in and the number of clicks to rotate. Then we can increase the pointer when rotating right and decrease the pointer when rotating left. We need to be careful when passing the number 0 or 99, which we can do by using modulo (%). This means that the resulting pointer number is always between 0 and 99.

def rotate(pointer:int, direction:str, clicks:int) -> int:
    return (pointer + clicks) % 100 if direction == 'R' else (pointer - clicks) % 100

What remains in part one is to check the value of the pointer after each instruction. If it is pointing at zero, we need to remember that and increase a counter. The value of this counter after executing all instructions will be the final answer for part one.

zero_pointer += 1 if pointer == 0 else 0

Part Two

Part two changes a small thing: we need to count the total number of times the dial points at zero every time. So not only after executing an instruction, but within an instruction as well.

That changes the logic a bit. The easiest thing is to just go click by click and checking if we're pointing at zero after each click. I've done this in a new function that accepts the current pointer position, the direction we need to turn in and the number of clicks. Within the function I loop as many times as the number of clicks, increase or decrease the pointer based on the direction and then check if the pointer is at zero. If so, I increase a count.

def zero_passes(pointer:int, direction:str, clicks:int) -> int:
    count = 0

    for _ in range(clicks):
        pointer = (pointer + 1) % 100 if direction == 'R' else (pointer - 1) % 100
        count += 1 if pointer == 0 else 0

    return count

After each instruction, I increase the total number of times the dial has passed zero. This total number is my answer two part two.

zero_pointer += zero_passes(pointer, direction, clicks)