2025 was my first year participating in Advent of Code. I'm planning document my solutions in a series of blog posts, mostly as an exercise for myself to explain my code and thought process to others. If you come across this, welcome! I hope my blog posts can help you in some way.
Question statement: https://adventofcode.com/2025/day/1
Solution: https://codeberg.org/ordinarycoder/aoc2025/src/branch/main/day1
Imagine there is a clock face, with 0 at the 12 o'clock position and go until 99. The hand of the clock initally points at 50.
The inputs consists of a series of lines, line begins wiht L or R follow by a
number. An L represents a counterclockwise
rotation of the hand, R a clockwise
rotation. The number represents how many times the arm should move in a
rotation. Each time the arms moves, it will point to the next or the
previous number depending on the rotation direction.
The goal is to find the numebr of times that the hand is pointing at 0 after each rotation. To do this, we need to determine the postion the hand is pointing at after each rotation.
First we consider the clockwise rotations. The intuition is to just
add the number to the current position. But we need to also handle the
case in which the sum is greater than 99, which doesn't exist on the
clock face. For example, say the hand is pointing at 50, and the number
is 51, the sum will be 101. When the arm is pointing at 99, the next
move will put it at 0, and the next put it at 1. So, the final position
after this rotation is 1. To do in code, we just use the modulo operator
with 100 as the divisor (% 100 in Python). This does
exactly what we wanted, keeping the result between 0 and 99.
For counterclockwise rotations, we minus the number from the current position instead of adding and then take modulo 100. Modulo works the same in case of negative numbers - i.e. replace an out of range number with an in-range one.
We perform either a clockwise or counterclockwise rotation for each input. Each input sets the current position to a new one. We count the number of times the current position is 0 after each input. And we came to the final answer.
The calculation of the position of is exactly the same as in part 1. The only difference is that we need to count how many time the hand passes over 0 during all the rotations.
First we consider the clockwise rotations. For a full rotation, i.e. number = 100. If the inital position is at 0, the sum will be 100, if the initial position is 99, the sum will be 199. That means if the sum is between 100 and 199, the hand has passed over 0 once. Likewise, 200 to 299 means twice, 300 to 399 mean 3 times and so on. We can simple take the floor of the sum of position and number divided by 100 and will have the count we wanted for one input.
Then for the counterclockwise rotations. A full rotation mean number = -100. If the initial position is a 0, the sum will be -100, if the initial position is 99, the sum will be - 1. That means if the sum is between -100 and -1, the hand has passed over 0 once. Likewise, -200 to -101 means twich, -300 to -201 means 3 times and so on. Also like in the clockwise case, we can simple take the floor of the sum of position and number and it by 100, which will yield the negative of the count. However there are 2 edge cases we need to consider:
Summing up all the count will get us to the final answer.