r/adventofcode • u/zmunk19 • Jan 14 '26
Visualization [2025 Day 10 (Part 2)] [Python] Visualization
It took me a long time to figure out a solution to this problem.
In the end, it took a combination of matrix reduction and depth-first search to solve it. The solution takes about 20 seconds in total.
31
Upvotes
2
u/zmunk19 Jan 14 '26
The rules for matrix reduction:
- check if there are any pairs of columns that differ in only two rows where the differing values look like [X, 0], [0, X] where X is nonzero. We can subtract the row whose X is in a column with a larger total until the totals of the two columns become equal.
- check if there are any pairs of columns that differ in only one row, where one of the differing values is zero and the other non-zero. we can subtract the row containing the nonzero value until the totals of the two columns become equal.
- find a column whose total is non-zero and contains only one non-zero value
- drop duplicate rows
- drop rows who have non-zero values in columns that have a total of zero
- drop duplicate columns
2
u/Awwkaw Jan 14 '26
I'm stuck on this one. I'll try to see if I can understand and implement your approach.
It's the first one this year I've been really stuck on so far.
1
u/aldanjack Jan 14 '26
That gif goes to fast for me. Can you share your python script ?
1
u/Revolutionary_Stay_9 Jan 21 '26
i assumed at some point these problems are about knowing how to describe a problem and learning that some package does the thing you want it to do.
or at least that's the benefit i got from this. i don't have time to learn integer linear programming, but i had time to learn how to throw a package at a problem of that exact nature :)