Guide

How Sudoku Solvers and Puzzle Generators Work

A solver answers a mathematical question: which completions, if any, satisfy the Sudoku constraints. A generator builds a complete valid grid and then removes clues while uniqueness remains established. Ninefold Logic runs both locally. There is no remote Sudoku API and no hardcoded answer key for arbitrary input. The solver workspace and the generator share one engine.

Constraint-based representation

Each cell holds 0 for empty or an integer from 1 through N. Displayed symbols 1–9 and A–G are a presentation of those integers. Occupancy masks record which values already appear in each row, column, and region. A candidate mask for an empty cell is the full symbol set minus those three occupancy masks.

Minimum remaining values

When several cells are empty, the solver chooses one with the fewest candidates. A cell with one candidate is forced. A cell with zero candidates is a dead end and triggers backtracking. Choosing the first empty cell in reading order also works, but it branches more.

Backtracking

The algorithm assigns a remaining candidate, updates masks, and continues. If a later cell has no candidate, it restores the previous state and tries the next candidate. When every cell is filled, the grid is verified: every unit contains each symbol once, and original clues are unchanged. Verification is not skipped just because the search filled the board.

4×4 demonstration

Start with an empty 4×4 grid. The first minimum-remaining cell has four candidates. Assign 1, propagate, and continue. If a contradiction appears, undo and try 2. An empty 4×4 has many solutions. The counter stops after two distinct completions and reports MULTIPLE SOLUTIONS. That is why an empty grid is not a published playable game.

Complete solution generation

Generation fills an empty grid with a seeded pseudo-random candidate order, then optionally applies symbol permutation, in-band row permutation, in-stack column permutation, and band or stack permutation. Transposition is used only when region geometry remains valid, so 6×6 2×3 regions are not silently flipped into 3×2. Pattern transforms do not sample the solution space uniformly, and this site does not claim that they do.

Clue removal

Copy the complete grid. Shuffle symmetry groups (none, 180° rotation, horizontal, vertical, or four-way). Remove a whole group, count solutions up to two, and restore the group if uniqueness is lost or unknown. Uniqueness is not assumed because one solution was found while generating the complete grid; the complete grid is one solution of a full board, but a punched board needs its own count.

Solution counting

The counter shares the solver’s masks and MRV selection. It stops at two solutions when the goal is uniqueness. Results are INVALID INPUT, NO SOLUTION, EXACTLY ONE SOLUTION, MULTIPLE SOLUTIONS, SEARCH LIMIT REACHED, or CANCELLED. SEARCH LIMIT REACHED means uniqueness is unknown. It is never relabeled unique to make a generator look successful.

Why one solution is not uniqueness

A search that stops at the first completion has not looked for a second. Playable games on this site require a count with max = 2 that returns exactly one. Custom solver input that has two completions shows both. An unsolvable but locally consistent 4×4—row 1 equal to 1,2,3,empty and a 4 already in column 4—returns NO SOLUTION.

Search limits

Difficult 16×16 puzzles can exceed a safe node budget. Workers keep the page responsive. Cancel stops the current job. A timed-out generation does not publish an unverified grid; it explains the failure or selects a versioned bundled fallback for daily puzzles and labels that fallback’s actual difficulty.

Logical solving versus search

The logical engine never uses hidden solution values for ordinary steps. If it stalls, search may still finish the grid. Difficulty classification records whether search was required. A stall is not reported as “solved logically.”

Questions

Is the solver guessing?
Backtracking tries candidates systematically. That is search, not a claimed human technique.
Can every 16×16 puzzle finish quickly?
No. The solver returns an honest limit status.
Do daily puzzles use Math.random?
No. Seeds come from the UTC date, size, difficulty, and generator version.

Related: logical techniques, daily challenge.

A practical check: paste the classic 81-character puzzle that begins 530070000 into the solver. The engine should report exactly one solution, preserve every original clue, and match the known completion that begins 534678912. Next, paste an empty 4×4 string of sixteen zeros. The status should be multiple solutions, and two distinct grids should appear. Finally, paste 1230000400000000. The first row needs 4, but column 4 already contains 4, so the status should be no solution. Those three outcomes—unique, multiple, none—are the only honest uniqueness answers besides invalid input, a reached search limit, or a cancelled job. Daily puzzles reuse the same pipeline with a seed derived from the UTC date so two visitors on the same generator version receive the same clues. If that seeded search cannot finish, a bundled fallback is chosen with the same hash, and the labeled difficulty is the fallback’s real class. Workers exist so a hard 16×16 search does not freeze the rest of the page. Cancel stops the current job; it does not invent a unique solution from a partial search.