Day 06 - Trash Compactor

parsinggridstate-machine

Language: Rust

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


This one was… frustrating.

Not because the individual pieces were hard, but because the problem forces you to think about the input in a slightly unusual way. Nothing complicated algorithmically, just awkward enough to slow everything down.


Part 1: Part 1 is actually pretty reasonable once the parsing is clear.

The last line contains operators (+ or *), and every column above it forms a vertical expression using that operator.

So the job is basically:

That turns into a simple nested loop:

for col in 0..num_problems {
    let mut col_value = numbers[0][col];
    for row in 1..numbers.len() {
        match operators[col] {
            '+' => col_value += numbers[row][col],
            '*' => col_value *= numbers[row][col],
            _ => {}
        }
    }
    total += col_value;
}

Nothing fancy. Just careful parsing and straightforward accumulation.


Part 2: I really didn’t enjoy this one.

The structure changes completely. Instead of clean numeric columns, the input now has to be treated character by character, effectively rotating the whole grid and interpreting vertical slices as expressions.

That means:

It’s conceptually simple, but in practice, it’s messy and easy to get wrong.

for col in columns {
    let trimmed = col.trim();

    if trimmed.ends_with('+') || trimmed.ends_with('*') {
        total += current_sum;
        current_op = trimmed.chars().last().unwrap();
        current_sum = match current_op {
            '+' => 0,
            '*' => 1,
            _ => 0,
        };
    }

    let num_str: String = trimmed.chars().filter(|c| c.is_ascii_digit()).collect();
    if !num_str.is_empty() {
        let num = num_str.parse::<u128>().unwrap_or(0);
        current_sum = match current_op {
            '+' => current_sum + num,
            '*' => current_sum * num,
            _ => current_sum,
        };
    }
}

It works. I’m still not happy with it.


Final thoughts Part 1 felt clean and logical, but part 2 feels more like wrestling with the input format than solving a real problem.

Sometimes the challenge isn’t algorithms or performance, it’s just not losing patience while parsing something weird.

Still count as solved… even if I don’t like how I got there.


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

No C writeup yet.