Advent of Code 2025 - Day 1Secret Entrance
| Problem statement | Source code | Tags: Brute forceMathematics
Part 1
I only learned that it's possible to simulate every single step of the dial—I guess that's more expected of day 1. Anyway, I implemented it the cleverer way, which is to update the position once per turn. Completing one turn resets the dial from 100 to 0, which is % 100. However, in Rust, % is remainder, which can return negative numbers if the LHS is negative. The modulo operation is provided by rem_euclid.
Part 2
Now we need to detect if a movement from to passes through 0. The trick is to imagine that the circular path is "unrolled" into a straight line, in which case every multiple of 100 corresponds to a position of 0. So we can calculate the number of multiples of 100 in the range (or when moving left). The number of multiples of 100 that are less than or equal to is . So the number of multiples of 100 in the range is (those less than or equal to , but not less than or equal to ). For , it's . Floor division (not rounding to zero) is provided by div_euclid.