Advent of Code 2025 is seriously kicking my ass. I’m really not sure why I persist in torturing myself. I’m really too stupid to be solving these things.
The first puzzle is here: Advent of Code 2025, Day 1, Part 1
I vowed that I wouldn’t use AI for any questions or help. I mostly met that goal, only cheated a bit with some Googling to confirm specific things. I was pleased with myself that I had a basic structure in my mind, modelling a dial with a struct type with a position field and then making a rotate method for it to represent the ability to change the position by moving left or right by a specified number of clicks. The type system in Rust really allows you to model things explicitly. I’m really happy that I can finally see that.
Here’s my code:
const DIAL_START_POSITION: i32 = 50;
const DIAL_RANGE: i32 = 100;
struct Dial {
position: i32,
}
impl Dial {
fn rotate(&mut self, direction: char, clicks: &i32) {
self.position = match direction {
'L' => (self.position - clicks).rem_euclid(DIAL_RANGE),
'R' => (self.position + clicks).rem_euclid(DIAL_RANGE),
_ => self.position,
}
}
}
fn main() {
let mut dial = Dial {
position: DIAL_START_POSITION,
};
// let puzzle_input = "L68\nL30\nR48\nL5\nR60\nL55\nL1\nL99\nR14\nL82";
let puzzle_input = include_str!("../puzzle1_input.txt");
let instructions: Vec<&str> = puzzle_input.split('\n').collect();
let mut count = 0;
for instruction in instructions.iter() {
let direction = instruction.chars().next().unwrap();
let clicks = &instruction[1..].parse::<i32>().unwrap();
dial.rotate(direction, clicks);
if dial.position == 0 {
count += 1;
}
}
println!("Number of times dial was at zero: {}", count);
}
The key is the rem_euclid() method. I knew I needed something like “wrapping” or “overflow” math, and that’s what Google ultimately led me to. When rotating “left” you’re seeking lower numbers, this is a subtraction operation. When rotating “right” your seeking higher numbers, this is an addition operation. You take the current position of the dial then add or subtract “clicks” to get the new position. The rem_euclid() operation gives you the result of the “wrapping” like a real dial does.
All you have to do then is load the input file, parse it to split the instructions, then loop over the instructions, rotating the dial by direction and clicks, counting when the dial is at 0.
Landed on the right answer on the first try.
My ass is well and truly kicked though by Part 2. Hope to be writing about that soon.
Comments