Advent of Code 2025 — Day 02
Language: Rust
Problem https://adventofcode.com/2025/day/2
Day 2 is a scan of numeric ranges and sum of IDs that have a repeated digit pattern.
The input is a single comma seperated line of inclusive ranges like 11-22. I split on commas,
then pare each start-end:
let (a, b) = range.split_once('-').unwrap();
let start: u64 = a.parse().unwrap();
let end: u64 = b.parse().unwrap();
Then each part does the same thing: iterate start..=end, filter by a predicate, sum,
and then sum accross ranges.
Part 1:
Invalid IDs are of the form XYXY (some digit sequence repeated twice). That means the
digit count is even, and the halves match.
if s.len() % 2 != 0 { return false; }
let (l, r) = s.split_at(s.len() / 2);
l == r
Part 2:
Now the number is invalid if it’s one block repeated k times, k >= 2. I try every possible
block length up to len/2, require divisibility, then verify all chunks equal the first:
for block_len in 1..=(len / 2) {
if len % block_len != 0 { continue; }
let block = &s[..block_len];
for i in (block_len..len).step_by(block_len) {
if &s[i..i + block_len] != block { ok = false; break; }
}
if ok { return true; }
}
Implementation shape Both parts follow the same pattern, only the predicate changes:
(start..=end)
.filter(|&n| is_repeated_at_least_twice(n))
.sum::<u64>()
Solution: https://github.com/Elyrial/AdventOfCode/blob/main/src/solutions/year2025/day02.rs
Approach (C)
Explain it.