Advent of Code 2025 - Day 6Trash Compactor
| Problem statement | Source code | Tags: String manipulation
Part 1
If we have a list of operators and a matrix of numbers, then for each operator, its result is just the sum()/product() of the numbers in the corresponding column: numbers.iter().map(|nums| nums[i]).sum().
Part 2
The intractable part is that each number is scattered across columns; if each one is in a row, the problem would be trivial. So we can simply transpose the input from:
To:
Now we can just go chunk by chunk to collect the operators and respective numbers. I start a new chunk whenever I encounter an operator, and push the numbers into the current chunk.
The arithmetic is the same as before.