Advent of Code 2025 Day 01

Link: https://adventofcode.com/2025/day/1

Challenge

Pointing at a fixed starting position (50) in a wrap around linear sequence (from 0 to 99). Count the number of times the pointer lands on the number zero (0).

Insight

A circular array can be represented as a 2D table with the pointer at the top and the values from 0 to 99 filling the table. Each row represents a cycle of 10 values, and the pointer moves through these values based on the rotations.

Pointer
0123456789
10111213141516171819
20212223242526272829
30313233343536373839
40414243444546474849
50515253545556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899

The input range from 0 to 99 can be simplified to 0 to 9 by taking modulo 10, since the value at any pointer position depends only on its position modulo 10. This works because the values repeat every 10 steps (0 through 9, then cycling back to 0).

In other words, the value at a given position is equal to the position modulo 10. For example, at position 52, the value is 2, since $52 \bmod 10 = 2$.

Pointer
0123456789

Then given a series of rotations (Left or Right), we can simulate the movement of the pointer L is negative (we subtract from the pointer’s position) and R is positive (we add to the pointer’s position). After each rotation, we check if the pointer lands on a position where the value is zero (i.e., the pointer’s position modulo 10 equals zero) and count how many times this happens.

So, from position 2, L4 would move the pointer 4 positions to the left, resulting in position 8 (since $2 - 4 = -2$ and $-2 \bmod 10 = 8$). We would check if this position corresponds to a value of zero by taking modulo 10.

Pointer
0123456789

From position 8, R3 would move it to position 1. We would check if these positions correspond to a value of zero by taking modulo 10.

The formula for updating the pointer’s position after a rotation is:

$$ \text{New Position} = \left( \left( \text{Current Position} + \text{Rotation} \right) \bmod 10 \right) $$

Simulation

The dial starts by pointing at 50.

P
0123456789
10111213141516171819
20212223242526272829
30313233343536373839
40414243444546474849
50515253545556575859
60616263646566676869
70717273747576777879
80818283848586878889
90919293949596979899

Simplified to modulo 10:

P
0123456789

The dial is rotated L68 to point at 82.

(Position + Rotation) % 10 = New PositionP
$(0 + (-68)) \bmod 10 = 2$0123456789

The dial is rotated L30 to point at 52.

(Position + Rotation) % 10 = New PositionP
$(2 + (-30)) \bmod 10 = 2$0123456789

The dial is rotated R48 to point at 0. Note: the dial points at 0 here, so we count this as 1 occurrence of landing on zero.

(Position + Rotation) % 10 = New PositionP
$(2 + (48)) \bmod 10 = 0$0123456789

The dial is rotated L5 to point at 95.

(Position + Rotation) % 10 = New PositionP
$(0 + (-5)) \bmod 10 = 5$0123456789

The dial is rotated R60 to point at 55.

(Position + Rotation) % 10 = New PositionP
$(5 + (60)) \bmod 10 = 5$0123456789

The dial is rotated L55 to point at 0. Note: the dial points at 0 here, so we count this as 2 occurrences of landing on zero.

(Position + Rotation) % 10 = New PositionP
$(5 + (-55)) \bmod 10 = 0$0123456789

The dial is rotated L1 to point at 99.

(Position + Rotation) % 10 = New PositionP
$(0 + (-1)) \bmod 10 = 9$0123456789

The dial is rotated L99 to point at 0. Note: the dial points at 0 here, so we count this as 3 occurrences of landing on zero.

(Position + Rotation) % 10 = New PositionP
$(9 + (-99)) \bmod 10 = 0$0123456789

The dial is rotated R14 to point at 14.

(Position + Rotation) % 10 = New PositionP
$(0 + (14)) \bmod 10 = 4$0123456789

The dial is rotated L82 to point at 32.

(Position + Rotation) % 10 = New PositionP
$(4 + (-82)) \bmod 10 = 2$0123456789

Because the dial points at 0 a total of three times during this process, the password in this example is 3.

Pitfalls / Stuck

Pattern / Concept Takeaway

Circular array simulation / state tracking


Solution

Built with Hugo
Theme Stack designed by Jimmy