Day 01 - Secret Entrance
Language: Rust
Problem https://adventofcode.com/2025/day/1
Part 1:
A safe with a circular dial numbered 0 to 99. The input is a list of rotation instructions
like L68 or R14. Parsing is painless in Rust: first character is the direction, the rest
is the number.
let dir: char = instruction.chars().nth(0).unwrap();
let value: i32 = instruction[1..].parse().unwrap();
The dial starts at 50 and wraps around after every move. Rust’s % can go negative when
the left side is negative, so I use the Euclidean trick to keep it in range:
dial = ((dial % 100) + 100) % 100;
From there it’s just simulating the instructions and counting how many times the dial lands
on exactly 0.
Part 2: Now I need to count every time the dial crosses zero, not just when it stops there.
Right turns are easy. Each time the dial wraps past 99 back to 0, that’s a crossing.
(dial + value) / 100 gives the count directly, then wrap the dial back into range.
Left turns take a bit more thought. The key question is how far the dial is from zero going
left. If it’s sitting at 0, a single left click wraps it to 99, so I treat that as 100
steps away. If the rotation is big enough to reach zero, that’s one crossing, and every full
100-step loop after that adds another.
At the end, the counter holds the total number of zero crossings.
Solution: https://github.com/Elyrial/AdventOfCode/blob/main/src/solutions/year2025/day01.rs
Language: C
Problem https://adventofcode.com/2025/day/1
Part 1:
A safe with a circular dial numbered 0 to 99. The input is a list of rotation instructions
like L68 or R14. Parsing in C means walking the input with a pointer. I read the
direction character first, advance past it, then let strtol consume the number. The nice
thing about strtol is that it moves the pointer to just after the number for you, so I
never have to manually skip digits.
const char *p = input;
char dir = *p; // 'L' or 'R'
p++; // step past the direction
value = strtol(p, (char **)&p, 10);
After each instruction I skip the newline and move on:
if (*p == '\n') p++;
The dial starts at 50 and wraps around after every move. C’s % can return negative values
when the left operand is negative, so I normalize with a Euclidean remainder:
dial = ((dial % 100) + 100) % 100;
From there it’s just simulating all the instructions and counting how many times the dial
ends up exactly at 0.
Part 2: Now I need to count every time the dial passes through zero, not just when it lands on it.
For right turns, each full wrap from 99 around to 0 is a crossing. (dial + value) / 100
gives the count, then the dial gets wrapped back into range.
Left turns are trickier. I need to know how far the dial has to travel before hitting zero
going left. If the dial is already at 0, one left click wraps it to 99, so I treat that
distance as 100. If the move is big enough to reach zero, that’s one crossing, then every
additional 100 steps adds another. After counting, the dial is updated and normalized as usual.
The counter at the end holds the total number of zero crossings.
Solution: https://github.com/Elyrial/AdventOfCode_C/blob/main/src/solutions/year2025/day01.c