Day 01 - Secret Entrance

parsingmath

Language: Rust

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


Day 1 is a straightforward warmup. The input consists of instructions like L68 or R14. Parsing this in Rust is simple: the first character gives the direction, and the rest of the string parses into an integer.

let dir: char = instruction.chars().nth(0).unwrap();
let value: i32 = instruction[1..].parse().unwrap();

The dial starts at 50. Each instruction moves it left or right, and because the dial wraps between 0 and 99, the value must always be normalized. Rust’s % operator can produce negative results, so a Euclidean remainder is used.

dial = ((dial % 100) + 100) % 100;

Part 1: Apply each instruction, normalize the dial, and count how many times it ends up exactly at 0.


Part 2: The dial starts at 50, and a counter tracks how many times it passes through 0.

For a right turn (R), every wrap from 99 back to 0 counts as a crossing. This can be counted directly using (dial + value) / 100, then the dial is wrapped back into range.

Left turns (L) are a bit trickier. What matters is how far the dial is from zero. If the dial is at 0, turning left wraps immediately, so it’s treated as being 100 steps away. If the rotation is large enough to reach zero, that’s one crossing, and every full loop after that adds another one. The dial is then updated and wrapped as usual.

The counter ends up holding the total number of times the dial crosses zero.


Solution: https://github.com/Elyrial/AdventOfCode/blob/main/src/solutions/year2025/day01.rs

Language: C

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


Day 1 is a straightforward warmup.

The input consists of instructions like L68 or R14. In C, I parse it by walking through the input with a pointer p. Here I usually think of p as “where I am currently reading”. I read the direction from *p, then advance the pointer, then parse the integer right after it.

const char *p = input;

char dir = *p;   // read current character ('L' or 'R')
p++;             // move forward to the number

value = strtol(p, (char **)&p, 10);

The strtol reads the number starting at p, and it also updates p to point to the first character after the number, which means i don’t have to manually skip digits. p always ends up in the right place for the next step.

At the end of each line I just skip the newline:

if (*p == '\n') {
    p++;
}

The dial starts at 50. Each instruction moves it left or right, and because the dial wraps between 0 and 99, the value must always be normaalized. In C (same as Rust), % can produce negative results when the left side is negative, so I normalize it with a Euclidean remainder.

dial = ((dial % 100) + 100) % 100;

Part 1: Apply each instruction, normalize the dial, and count how many times it ends up exactly at 0.


Part 2: Part 2 is about counting how many times the dial crosses 0, not just where it ends.

For right turns (R), every wrap from 99 back to 0 counts as a crossing. This can be computed directly using integer division on dial + value, which tells how many full wraps occurred. The dial is then wrapped back into range.

Left turns (L) is a bit trickier. What matters is how far the dial currently is from zero. If the dial is at 0, turning left wraps immediately, so it is treated as being 100 steps away. If the rotation is large enough to reach zero, that counts as one crossing, and every full loop after that adds another one. After counting crossings, the dial is updated and normalized as usual.

At the end, the counter contains the total number of times the dial crossed zero.


Solution: https://github.com/Elyrial/AdventOfCode_C/blob/main/src/solutions/year2025/day01.c