I recently started re-acquainting myself with Python, and I thought solving the GHCQ nonogram would be a good problem to dive in to. Here’s what I came up with.
Method
The puzzle is a 25×25 nonogram. I decided to write a program that uses the same method that I would use if solving the puzzle by hand:
- For each row and column, generate the set of patterns that match the given clues
- For each row, eliminate the patterns that don’t match the cells we already know
- For each row, deduce the known cells based on the reduced pattern set
- For each column, eliminate the patterns that don’t match the cells we already know
- For each column, deduce the known cells based on the reduced pattern set
- Go back to 2. and repeat, unless we’ve solved it
Code
I call it “yangs” - Yet Another NonoGram Solver.
View the Jupyter notebook on nbviewer or download a .py file fron GitHub