How a Nonogram Solver Works

After reading this you will know exactly how a nonogram solver deduces each cell, why line overlap forces filled squares, when the solver switches to contradiction testing, and how to read the running log so you can learn the technique instead of just copying the answer.

What a nonogram is and one forced deduction

A nonogram (also called picross, griddler, or hanjie) is a grid where numbers along each row and column tell you the lengths of the filled runs in that line, in order, with at least one empty cell between runs. Solve every line consistently and the filled cells form a picture.

Here is the hook. Take a row of 10 cells with the single clue 8. One run of 8 must fit somewhere in 10 cells. It can start at cell 1 (covering 1 to 8) or as late as cell 3 (covering 3 to 10). Slide the block between those two extremes and one fact never changes: cells 3, 4, 5, 6, 7, and 8 are filled in every valid position. That overlap is forced. You can mark those six cells immediately without knowing the exact placement. A nonogram solver does this overlap reasoning for every line, then repeats until the picture is complete.

When to use the solver and when not to

Use the solver when you are building puzzles and need to confirm that a clue set has exactly one solution. A published nonogram with two solutions is a broken puzzle, and the solver flags that. Use it when you are stuck on a hard line and want to see the specific deduction you missed, since every step names the line and the cells. Use it to check a scanned or hand-typed clue set before you print 30 copies for a classroom.

Do not use it as a shortcut that skips the learning. The value of the log is that it shows the reasoning in the same order a careful human would find it. Read the steps, then try the next line yourself before revealing it.

If you are designing puzzles, solve your draft after every clue change. A single edited number can turn a unique puzzle into one with four solutions, and you want to catch that before layout, not after.

The overlap formula and why it works

The core of line logic is the overlap between the leftmost and rightmost packing of the clues. Consider a line of length L with a single run of length b. The run can start as early as cell 1 and as late as cell L - b + 1. The cells that are filled in both extremes are exactly the ones forced.

\text{forced} = 2b - L

Here b is the run length and L is the line length. If 2b - L is positive, that many cells in the middle of the run are forced filled. In the earlier example b = 8 and L = 10, so 2 \cdot 8 - 10 = 6 cells are forced, matching the six we found.

For multiple clues the idea generalizes. Pack all runs as far left as possible, then as far right as possible, and take the cell-by-cell intersection. The solver goes further: it enumerates every arrangement that fits both the clues and the cells already known, then keeps any cell that is filled in all of them (forced filled) or empty in all of them (forced empty). That is the full intersection, stronger than the simple two-extreme overlap because known cells prune many arrangements.

In a line of length 10, a run shorter than 6 forces nothing by itself, while a run of 10 fills the whole line. Each extra cell of run length adds two forced cells.

In a line of length L, a single run of length b is forced in its middle by 2b - L cells when that value is positive. For L = 15 and b = 10, that is 5 forced cells; for b = 8 it is 1; for b = 7 it is 0.

Worked example using the demo data

Load the demo and the solver starts from the default clue set. The method below reproduces its first deductions on any small puzzle. Take a 5 by 5 grid with these clues.

Clues for a 5 by 5 example
Line12345
Row clue51 11 11 15
Column clue51 11 11 15

Solving the border square step by step

  1. Row 1 has clue 5 in a line of length 5, so 2 \cdot 5 - 5 = 5 cells are forced. Fill the entire top row.
  2. Row 5 has clue 5 as well. Fill the entire bottom row.
  3. Column 1 has clue 5. Fill the whole left column. Column 5 has clue 5. Fill the whole right column.
  4. Now look at row 2, clue 1 1. Column 1 already forced cell (2,1) filled, and column 5 forced cell (2,5) filled. Two runs of length 1 are placed. The clue is satisfied, so cells (2,2), (2,3), (2,4) must be empty.
  5. The same logic clears the interior of rows 3 and 4. The picture is a hollow square, and the solution is unique.

The log for this puzzle names each step: "Row 1: cells 1-5 must be filled", then "Column 1: cells 1-5 must be filled", then "Row 2: cell 3 must be empty". Every filled or emptied cell is justified.

Reading and interpreting the log

The running log distinguishes two kinds of steps, and the distinction matters if you want to learn the technique.

Line logic
A deduction that follows from one row or one column alone, given the cells already known. These are the steps you should aim to find yourself. Most human-solvable puzzles are complete with line logic only.
Contradiction search
When no single line makes progress, the solver picks one undecided cell, assumes it is filled, and runs line logic. If that assumption forces an impossible line, the cell must be empty. These steps are labeled as contradiction search, not line logic, so you know the puzzle needed a guess-and-check leap at that point.

A puzzle that solves entirely with line logic is usually rated easy to medium. If you see several contradiction steps, the puzzle is genuinely harder, and that is useful feedback when you are grading your own designs.

The solver reports impossible clue sets by naming the offending line, for example "Row 4: no arrangement of 3 2 fits in 5 cells". A run total plus the mandatory gaps cannot exceed the line length: 3 + 1 + 2 = 6 \gt 5, so that line is impossible on its own.

Common mistakes when entering clues

Most failed solves come from input, not logic. Watch for these.

  • Wrong line length. A 15-wide puzzle needs 15 column clues. If you paste 14 lines the geometry is off and the solver rejects it.
  • Missing gaps in your head. The clue 2 3 in a 5-cell line needs 2 + 1 + 3 = 6 cells and does not fit. If you meant one run, type 5, not 2 3.
  • Zero versus blank. An empty line means a fully blank row or column. Enter 0 if the tool expects an explicit zero, and leave nothing ambiguous.
  • Trusting a multiple-solution puzzle. If the solver warns that more than one solution exists, one is shown, but your puzzle is not publishable as is. Add or change a clue and solve again.

A very common error is swapping rows and columns. If the picture comes out transposed, you pasted the column clues in the row box. Check the corner: the first row clue describes the top row read left to right, and the first column clue describes the leftmost column read top to bottom.

Related solvers on this site

If you like puzzles that reward constraint reasoning, two others use the same explain-every-step approach. The Sudoku Solver names the human technique behind each placement, from naked singles to hidden pairs. The Kakuro Solver spells out the sum-combination reasoning for cross sums, which is close in spirit to nonogram line logic because both narrow a line by intersecting all arrangements that fit a numeric constraint.

Frequently asked questions

How big a nonogram can the solver handle?

Up to 25 by 25. Line logic scales well because it works one line at a time, and most published puzzles up to that size solve in well under a second in the browser.

Why does the solver say my puzzle has more than one solution?

Because the clues do not pin down a single picture. At least two different filled patterns satisfy every row and column clue. The tool still shows one valid solution, but you should tighten the clues before publishing.

Does contradiction search mean the puzzle needs guessing?

It means line logic alone stalled at that point, so the solver tested one cell both ways. A skilled human would do the same. Puzzles that need contradiction steps are harder but still have a unique, logically forced answer.

Can I pre-fill cells I already solved?

Yes. Click cells to mark them filled or empty before solving. The solver treats those as known and prunes arrangements accordingly, which often makes the remaining deductions faster and shorter.

Is my puzzle sent anywhere?

No. The solver runs entirely in your browser, so your clues and grids never leave your device.