Day 04 - Printing Department
Language: Rust
Problem https://adventofcode.com/2025/day/4
Part 1:
The input is a grid where @ is a paper roll and . is empty space. A forklift can only
reach a roll if it has fewer than 4 neighboring rolls out of the 8 possible adjacent cells.
I parse the input into a 2D grid, then for every @ cell I check all 8 directions and count
how many neighbors are also @. If the count is less than 4, the roll is accessible.
let dirs = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)];
Neighbors outside the grid bounds are just ignored. The answer is the total count of accessible rolls.
Part 2: Now it becomes a simulation. Once a roll is accessible it gets removed, which can expose previously blocked rolls, which can then also be removed, and so on until nothing is left to clear.
The loop collects all currently accessible rolls, removes them by replacing @ with .,
and keeps running until there’s nothing left to remove:
loop {
let to_remove = find_accessible(&grid);
if to_remove.is_empty() {
break;
}
for (r, c) in to_remove {
grid[r][c] = '.';
}
total_removed += to_remove.len();
}
The grids are small enough that brute forcing every iteration is fine. Part 2 mostly just needed a small restructure of the Part 1 logic into a helper function to keep the loop clean.
Solution: https://github.com/Elyrial/AdventOfCode/blob/main/src/solutions/year2025/day04.rs
No C writeup yet.