Day 06 - Trash Compactor
Language: Rust
Problem https://adventofcode.com/2025/day/6
Part 1:
A math worksheet where numbers are stacked vertically in columns and the operator (+ or *)
sits at the bottom of each column. The goal is to evaluate each column top to bottom and sum
all results.
Once the parsing is clear, this is a straightforward 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 algorithmically interesting, just careful parsing and accumulation.
Part 2: This is where it got frustrating. The structure changes completely. Instead of clean numeric columns, the input has to be read character by character, with vertical slices treated as expressions. That means building column strings from raw text, walking them left to right, tracking the current operator and running value, and flushing totals whenever a new operator column appears.
Conceptually simple, but messy in practice 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. Sometimes the challenge isn’t the algorithm, it’s just not losing patience while parsing something weird.
Solution: https://github.com/Elyrial/AdventOfCode/blob/main/src/solutions/year2025/day06.rs
No C writeup yet.