← Nesim Apps

Is Your Nonogram Unique? Line Solvers and No-Guess Puzzles

By Nesim Razon, independent mobile developer · 2026-11-23

#Algorithms#Level generation#Game design

A nonogram looks simple: numbers on the edges, squares to fill. The hard part for a puzzle maker is making sure the picture has one answer and that a player can reach it by pure logic. Here is how a small line solver does that check, and how I use it to generate snowflake pictures in a winter puzzle app.

What a nonogram is

A nonogram is a grid with numbers beside every row and above every column. Each number says how many filled squares in a row sit together on that line. Between two groups there is at least one empty square.

Example for a line of 5 squares:

When every row and column is correct, the filled squares form a picture. In Snowlings, the winter picture appears once the numbers all match.

Why a unique solution matters

Take a 2 by 2 grid where every row clue and every column clue is 1. Two pictures fit: one diagonal or the other. The clues cannot tell them apart, so the player must guess, and a wrong guess shows up only much later.

That is the failure a puzzle maker wants to avoid. If a puzzle has several answers, the player cannot be sure any move is certain, and the "just think harder" promise breaks. A unique answer means each step can be justified by the clues alone.

The line solver: find the certain cells

The core idea is to look at one line at a time. List every way the clue can be laid out on that line without breaking the cells already known. A cell that is filled in every arrangement is certainly filled. A cell that is empty in every arrangement is certainly empty. Everything else stays unknown.

The classic shortcut is the overlap. With clue 7 on a line of 10 squares, the block can start anywhere from the first to the fourth square. Slide it all the way left and all the way right and compare:

The solver in the Snowlings code does not use only this shortcut. It first checks with memoized recursion that the clue can be placed at all given the known cells, then walks through the valid placements and records, for every square, whether it can be filled and whether it can be empty. If it can only be filled, it becomes filled. If it can only be empty, it becomes empty. If the clue cannot be placed at all, the function returns null, which means a contradiction.

Repeat over rows and columns

One pass over a line rarely finishes the picture, but what you learn in a row helps the columns, and the other way round. The check is a loop, written here in plain steps:

At the end, look at the grid. If no unknown square is left, the puzzle is solvable by line logic alone. If unknown squares remain, like in the 2 by 2 example, the line solver is stuck and a human would have to guess or use deeper reasoning. If a line reports a contradiction, the clues describe no picture at all.

The no-guess rule, and why it implies uniqueness

In the Snowlings nonogram code the rule is written in the file header: a picture becomes a level only if the line solver solves it completely. The function that checks it is called lineSolvable.

This also proves uniqueness. Every square the solver fills is forced by the clues, so any valid picture must agree with it. If all squares end up decided, only one picture is possible. The reverse is not true: a puzzle can have a single answer and still need harder reasoning than lines. The rule is therefore stricter than uniqueness, which is the point: it removes guessing, not just ambiguity.

The rule is enforced in tests. One test checks that the generated 10 by 10 pictures for ids 0 to 4 and a 12 by 12 picture are line-solvable, another test requires at least three of the hand-drawn pictures to pass, and a level test asserts lineSolvable for the nonogram levels it builds. The hand-drawn pictures that fail are simply filtered out of the game.

Generating symmetric snowflake pictures

Hand-drawn pictures are limited, so the generator makes decorative snowflake-like ones. The recipe is short:

The seed comes from the level id, the size and the attempt number, so the same level id always gives the same picture on every device. After 300 failed attempts the generator relaxes to mirroring left to right only. In practice the symmetric version is expected to succeed first; I have not measured how many attempts it usually needs, so I will not quote a number.

Levels, hints and where this runs

The same solver decides what players see. In free play the first three pictures are 5 by 5 teaching pictures, then the hand-drawn 10 by 10 ones, then generated pictures: 10 by 10 below index 20 and 12 by 12 after that. In the Advent calendar the first nonogram door uses a 5 by 5 picture, and days 24, 25 and 31 have fixed pictures: a gift, a tree and a star.

The hint button works differently from the solver. It does not reason; it compares your marks with the stored picture and fixes the first wrong or missing square it finds, scanning row by row. That is fine because the picture is known to be the one solvable answer.

If you like this kind of puzzle, the nonogram game in Snowlings is built on exactly this solver, so you can finish every picture without guessing.

Frequently asked questions

What is a nonogram?

A grid puzzle where the numbers beside each row and column tell how many filled squares sit together on that line. Solving it reveals a picture.

How can I tell if a nonogram has only one solution?

Run a solver. If a line solver alone fills every square, the answer is unique. If it gets stuck, the puzzle may have several answers or need deeper reasoning.

What is the overlap method?

Place the clue at its leftmost and rightmost positions on the line. Squares covered in both positions are certainly filled.

Does a unique solution mean no guessing is needed?

Not always. A puzzle can have one answer but still need reasoning beyond single lines. A line-solvable puzzle needs none.

Why do generated nonograms use symmetry?

Mirroring a random quarter gives a tidy snowflake-like picture, and the solver check removes the ones that would need guessing.

More from the blog