// HACKER NEWS — CYBERSECURITY
Solving a corn puzzle with CP-SAT
One random Friday at RC, I was bored and playing around with a
puzzle someone had 3d printed:
It’s a physical puzzle consisting of a white “cob” with grooves in it and a
bunch of “corn” pieces, each made of 3-10 kernels stuck together in a particular
shape, that can slide into the grooves. The goal is to slide them on so that
they fit together exactly, with no overlaps and no gaps.
Like all software engineers in the year of our lord 2026, I quickly got tired of
solving the puzzle myself and asked Claude to do it for me:
After a little bit of wrangling - it turns out computer vision isn’t quite
that good yet, so I had to clarify some of the piece shapes - Claude wrote a
script in python that gave a solution.
It was much better than I would have written myself, and I ended up learning
from it.
If I was solving this problem myself, I would naively reach for recursive
backtracking. If you’re a programmer, you’ve probably seen this algorithm in an
intro CS class.
Basically, it’s the brute force approach - try something at random, then try
something else, keep going until the puzzle is solved. If you ever get stuck and
there are no legal moves left, undo your last move and try again from there. If
all moves from that point fail, undo another move, and so on.
This is just an organized way of trying all the options, and it does admit some
nice optimizations based on the structure of the problem. For example, you can
take into account the symmetry that rotating the cob doesn’t change the solution
in any way, or fail early if you ever isolate a single kernel space on its own
(so that no piece can cover it). So a well thought-out approach to backtracking
would likely work.
However, when I looked at Claude’s script I realized from the first line that I
was being dumb:
Instead of backtracking, Claude just imported an industrial-strength library
made to solve these sorts of problems. OR-Tools
CP-SAT is put out by
Google and is made for solving constrained optimization problems, as well as
satisfiability problems like this one.