Advent of Code 2025 — Day 04

Language: Rust

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


Day 4 is a grid-based problem. The input is an ASCII map where @ represents a roll of paper and . is empty space. Everything resolves around checking the 8 neighboring cells around each position.


Part 1: A paper roll is accessible if:

This is a straightforward bruteforce scan:

  1. Parse the input into a 2D grid of chars.
  2. For every cell, look at all 8 direction.
  3. Ignore neighbors that fall outside the grid.
  4. Count how many adjecent @ cells there are.
let dirs = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)];

If the count is < 4, the roll is accessible. The answer for part 1 is just how many such cells exist.


Part 2: Part 2 builds directly on part 1, but turns it into a simulation.

Once a roll is accessible, it can be removed. Removing rolls may expose new rolls, which can then also be removed. This continues until no more rolls are accessible.

I had to slightly restructure the code for this one:

The loop structure ends up very clear:

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();
}

Since the grid sizes are small, bruteforcing is fast enough to solve this problem.


Final thoughts Part 1 is a clean, simple bruteforce grid scan. Part 2 required a small rethink of the structure, but the result is easier to read and reason about when breaking down the logic into helper functions.


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

Approach (C)

Explain it.