nonogram solver

I used to subscribe to GAMES magazine when I was a kid. A few years ago, I realized GAMES was still being published and got myself a subscription. One of my favorite recurring features was the nonogram (AKA, picross) puzzles. When I got my first new issue, the nonograms were still there and I dug in.

Each puzzle gives you clues for sequences of colored squares in the rows and columns of a grid. A “7” by itself on the left-hand side means there’s a span of seven consecutive colored squares somewhere in that row. If there are multiple numbers, there are multiple spans of consecutive colored squares in the given order (with at least one white square in between). Same thing for columns, but vertical.

Here’s an example (source):

After solving a few nonograms, I got a little bored. They were more repetitive than I’d remembered. It was the same handful of procedures, over and over. I was teaching myself Python at the time and so, to spice things up, I decided to write a script to solve them for me.

Here’s what I came up with: It’s not the most efficient algorithm, but I did set it up to export the results as an animated GIF. The bird GIF up top was generated with data from the blank puzzle shown above.

And here’s a bonus GIF of a Yellow Submarine puzzle: