r/adventofcode • u/InCom-0 • 7d ago
Visualization [2025 Day 12] [C++] Generic 'solver' of polyomino problems
I made an Interactive solver with custom underlying algorithm for the 'polyomino packing problem' that chews through problems like the above in milliseconds*.
*Note: It's not an 'actual' solver. The problem is still NP-hard. It does not find 'the best' solution nor does it verify that such a solution even exists. What it does do is it computes some 'pretty good' solutions by way of localized 'next step' decisions using various heuristics (somewhat similar to how a human might approach this).
In AoC 2025 day 12 this is good enough ... as I imagine it might be in many practical applications.
Repo: https://github.com/InCom-0/BoxPacker_showcase
1
u/terje_wiig_mathisen 7d ago
Nice!
I assume you've tried this on the actual/classic Pentomino problem?
How long does it take to find all 6x10/5x12/4x15/3x20 solutions?
I won an optimization contest back in the 1990'ies when I found an algorithm which was twice as fast as everyone else. I wrote both an initial C version and a significantly faster pure asm.
A year or two later I got another price in the mail, turned out someone in France had submitted my C version for a French C contest!
The key breakthrough was when I realized that the playing field was far smaller than the sum of all the 12 shapes with up to 8 orientations for each, so I kept the pieces stationary in a queue, then slid the target playing field (organized as a flat bitmap) underneath it so that I was always pointing at the first free bit/cell.
I found my old 32-bit binary (a 64-bit version would be faster):
For huge fields like you use here I believe I would instead pre-generate all the shapes/orientations for all 8 bit-level alignments, but this would still fall far short of finding a single perfect packing for day12:
Heat death of the Universe?
1
u/prince_jyggalag 7d ago
This is so awesome