Sudoku RoyaleDownload

The Mathematics Behind Sudoku

English

Sudoku is far more than a casual puzzle: it sits at the intersection of several deep areas of mathematics. There are exactly 6,670,903,752,021,072,936,960 (approximately 6.67 sextillion) valid completed sudoku grids, as proven by Bertram Felgenhauer and Frazer Jarvis in 2005. The minimum number of clues needed for a unique solution is 17, proven computationally by Gary McGuire et al. in 2012. Sudoku is an NP-complete problem in its generalized form, connects to graph coloring and constraint satisfaction theory, and possesses rich symmetry groups. These mathematical properties explain why sudoku generates such satisfying puzzles and why it continues to attract serious academic research.

Counting Valid Sudoku Grids: 6.67 Sextillion

One of the first mathematical questions about sudoku is straightforward: how many valid completed grids exist? A valid completed grid is a 9×9 arrangement where every row, column, and 3×3 box contains the digits 1–9 exactly once (following the standard sudoku rules).

In 2005, mathematicians Bertram Felgenhauer (University of Sheffield) and Frazer Jarvis (University of Sheffield) computed the exact answer: 6,670,903,752,021,072,936,960 valid sudoku grids. This is approximately 6.67 × 10²¹, or 6.67 sextillion.

Their approach combined careful mathematical analysis with computational enumeration. They first fixed the top band (the first three rows) and counted the valid completions for the remaining six rows. By exploiting symmetries within bands and stacks, they reduced the computation to a manageable size. The calculation was independently verified by Ed Russell using a different method, confirming the result.

To put this number in perspective: if every person on Earth (8 billion people) solved one unique sudoku grid per second, it would take over 26,000 years to exhaust all valid grids. The sheer number explains why you'll never run out of fresh sudoku puzzles: the space of possible grids is, for all practical purposes, inexhaustible.

Essentially Different Grids: Symmetry and Equivalence

Many of those 6.67 sextillion grids are, in a meaningful sense, "the same puzzle" transformed by operations that don't change the solving experience. Mathematicians define an equivalence class of sudoku grids as a set of grids that can be transformed into each other through:

  • Relabeling digits: Swapping all 3s and 7s, for instance, doesn't change the puzzle's logic.
  • Permuting rows within a band: Swapping two rows within the same 3-row band preserves all box constraints.
  • Permuting columns within a stack: Similarly, swapping columns within the same 3-column stack is valid.
  • Permuting bands: Swapping entire 3-row bands (top, middle, bottom) preserves the structure.
  • Permuting stacks: Swapping entire 3-column stacks is also valid.
  • Transposing the grid: Reflecting the grid along the main diagonal (swapping rows and columns) preserves all constraints.

These operations form a mathematical symmetry group with 3,359,232 elements (9! digit relabelings × 6³ row/column permutations within bands/stacks × 6² band/stack permutations × 2 for transposition). Using this symmetry group, Jarvis and Russell computed that there are approximately 5.47 billion essentially different sudoku grids, still a huge number, but roughly a trillion times smaller than the total count.

Minimum Clues in Sudoku: Why 17?

A sudoku needs at least 17 clues (given digits) to have a single solution. Gary McGuire, Bastian Tugemann and Gilles Civario proved this by showing that no 16-clue puzzle with a unique solution exists. They posted the result on 1 January 2012 and published the full paper, "There is no 16-Clue Sudoku", in Experimental Mathematics in 2014. Newspaper puzzles usually give around 25 clues, the paper notes.

A 17-clue sudoku

14254783193425186
A 17-clue sudoku, the first puzzle in Gordon Royle's collection. We checked it with a brute-force solver: it has exactly one solution.

This puzzle comes from Gordon Royle's collection of 17-clue sudokus (Gordon Royle and The University of Western Australia, CC BY 2.5). Royle, a mathematician at the University of Western Australia, found most of the 49,151 puzzles in the list himself, with a few hundred sent in by other solvers. As a string, row by row with 0 for blanks: 000000010400000000020000000000050407008000300001090000300400200050100000000806000

Can a sudoku have 16 clues?

Not with a unique solution. You can place 16 digits in a grid, but the result always has two or more solutions, so it is not a proper sudoku. Delete the 8 in the bottom row of the puzzle above and our solver finds a second solution at once. The 2012 proof shows this happens for every possible set of 16 clues in every possible grid.

How the proof works

The proof is a computer search, but a clever one. Checking every 16-clue pattern directly would be hopeless, so the team broke the problem into three steps:

  1. Cut down the grids. Relabelling digits, swapping rows within a band, swapping bands, transposing and similar moves turn one solved grid into another with matching puzzles. That leaves 5,472,730,538 essentially different grids to search (Russell and Jarvis, 2006), instead of all 6.67 sextillion.
  2. Find the unavoidable sets in each grid. An unavoidable set is a group of cells whose digits can be shuffled to give another valid grid. In the paper's example, four cells in rows 1 and 2 hold a 5 and a 9 each; swapping the 5s and 9s in just those cells gives a second valid grid, so any proper puzzle must give at least one of those four cells as a clue. A typical grid has around 360 unavoidable sets of up to 12 cells.
  3. Look for 16 cells that hit them all. A set of clues that touches every unavoidable set is called a hitting set. The program, called checker, listed every 16-cell hitting set in each grid and ran each one through a sudoku solver. None had a unique solution.

The new checker took about 3.6 seconds per grid. The whole search used about 7.1 million core-hours on the Stokes cluster at the Irish Centre for High-End Computing, running from January to December 2011, roughly 800 processor-years of work. The easy part has a one-line proof: with 7 clues, at least two digits never appear, and swapping those two digits everywhere gives a second solution. When the paper was written, nobody had a proof without computers even that 8 clues are too few.

Most grids do not contain a 17-clue puzzle at all. The puzzles on Royle's list solve to only 46,294 distinct grids, out of 5.47 billion. Smaller sudokus follow the same pattern: the paper lists a minimum of 4 clues for 4x4, 8 for 6x6 and 14 for 8x8.

Minimum vs minimal puzzles

The two words sound alike but mean different things. The minimum is the smallest number of clues any sudoku can have: 17. A minimal puzzle is any proper puzzle where every clue is needed, so removing any single clue gives more than one solution. Every 17-clue puzzle is minimal, because removing a clue would leave 16. Minimal puzzles can have many more clues, though.

692438261464319815227434315
A minimal puzzle with 27 clues and the same solution as the 17-clue puzzle above. We checked with a brute-force solver that removing any one of its 27 clues allows more than one solution.

We made this one by starting from the solved grid of the 17-clue puzzle and deleting digits at random, keeping each deletion only while the puzzle still had one solution. It stopped at 27 clues, none of which can go, yet a 17-clue puzzle for the same answer exists. So "minimal" describes a single puzzle, while "minimum" describes all sudokus.

Sudoku as a Constraint Satisfaction Problem

In computer science, sudoku is a canonical example of a constraint satisfaction problem (CSP). A CSP consists of:

  • Variables: The 81 cells of the grid.
  • Domains: Each variable can take a value from {1, 2, 3, 4, 5, 6, 7, 8, 9}.
  • Constraints: All-different constraints on each row (9 constraints), each column (9 constraints), and each box (9 constraints), for 27 constraints total.

CSP solvers use techniques like arc consistency (eliminating values that can't participate in any valid solution), forward checking (propagating the effects of each assignment), and backtracking search (trying values and reverting when a contradiction is found). These algorithmic techniques directly correspond to human solving strategies: arc consistency is analogous to naked pairs and hidden singles, while backtracking corresponds to trial-and-error (which human solvers call "guessing" and generally avoid).

Modern CSP solvers can solve any valid 9×9 sudoku puzzle almost instantaneously. The challenge for computer scientists lies not in solving individual puzzles but in studying the computational complexity of sudoku as a general problem class.

NP-Completeness: Sudoku Is Computationally Hard

In 2003, Takayuki Yato and Takahiro Seta of the University of Tokyo proved that the generalized version of sudoku (solving n²×n² grids with n×n boxes) is NP-complete. This is one of the most important classifications in computational complexity theory.

NP-completeness means two things:

  1. Solutions can be verified quickly: Given a proposed solution to a sudoku puzzle, you can check whether it's correct in polynomial time: just verify that each row, column, and box contains no duplicates.
  2. Finding solutions is (probably) hard: No algorithm is known that can solve all generalized sudoku puzzles in polynomial time. If such an algorithm existed, it would prove P = NP, resolving one of the most important open problems in mathematics and computer science (worth a $1 million Millennium Prize from the Clay Mathematics Institute).

For standard 9×9 puzzles, NP-completeness is somewhat academic: the fixed size means that even brute-force algorithms finish quickly. The theoretical importance lies in what it tells us about the nature of sudoku: it belongs to the same computational class as some of the hardest optimization problems in the world, including the traveling salesman problem, Boolean satisfiability, and graph coloring.

Graph Coloring and Sudoku

Sudoku has an elegant connection to graph theory. If you construct a graph where each of the 81 cells is a node, and you draw an edge between any two nodes that share a row, column, or box, you get the sudoku graph. Each node is connected to exactly 20 other nodes (8 from its row, 8 from its column, and 4 additional from its box that aren't in the same row or column).

Solving a sudoku puzzle is equivalent to graph coloring this graph with 9 colors, where the given digits are pre-assigned colors. Graph coloring is itself NP-complete for general graphs, which provides another proof of sudoku's NP-completeness.

The graph coloring perspective illuminates why certain solving techniques work. For instance, the X-Wing technique exploits a specific subgraph structure where the coloring constraints in one part of the graph force colors in another part. Understanding sudoku as graph coloring also suggests new solving strategies borrowed from graph theory algorithms.

Mathematical ConceptConnection to SudokuKey Result
CombinatoricsCounting valid completed grids6.67 sextillion grids (Felgenhauer & Jarvis, 2005)
Symmetry groupsEquivalence classes of grids~5.47 billion essentially different grids
Extremal combinatoricsMinimum clues for unique solution17 clues minimum (McGuire et al., 2012)
Computational complexityGeneralized sudoku is NP-completeProven by Yato & Seta, 2003
Graph theorySudoku as graph coloring81-node graph with chromatic number 9
Constraint satisfactionSudoku as a canonical CSPSolvable via arc consistency + backtracking
Latin squaresSudoku as constrained Latin squareEuler's foundation (1783)

Latin Squares: Sudoku's Mathematical Ancestor

A Latin square of order n is an n×n grid filled with n different symbols such that each symbol occurs exactly once in each row and each column. Sudoku is a Latin square of order 9 with the additional constraint that each 3×3 box also contains all 9 symbols.

Leonhard Euler studied Latin squares in the 18th century, investigating questions about orthogonal Latin squares (pairs of Latin squares that can be superimposed with all symbol-pairs appearing). His work laid the foundation for what would eventually become sudoku nearly 200 years later.

The number of Latin squares of order 9 is approximately 5.52 × 10²⁷, vastly more than the 6.67 × 10²¹ valid sudoku grids. The ratio tells us that the box constraint eliminates roughly 99.9999% of all possible Latin squares. This dramatic reduction is precisely what makes sudoku puzzles interesting: the box constraint interacts with the row and column constraints to create a much tighter logical structure than a plain Latin square.

Algorithmic Approaches to Solving Sudoku

Computer scientists have developed many algorithms for solving sudoku, each illustrating different computational principles:

Backtracking

The simplest algorithmic approach: fill cells one by one, and when a contradiction is reached, backtrack to the most recent decision and try a different value. With good heuristics (like choosing the most constrained cell first), backtracking can solve any 9×9 sudoku in milliseconds.

Constraint Propagation

More sophisticated algorithms use constraint propagation to reduce the search space before backtracking. Peter Norvig's famous essay "Solving Every Sudoku Puzzle" demonstrates how combining constraint propagation with depth-first search creates an elegant and efficient solver in just a few dozen lines of code.

Dancing Links (DLX)

Donald Knuth's Algorithm X with Dancing Links (DLX) solves sudoku by reformulating it as an exact cover problem: find a subset of rows in a binary matrix such that each column contains exactly one 1. This approach is particularly elegant because it solves sudoku as a special case of a general combinatorial problem, and it's extremely efficient in practice.

SAT Solvers

Sudoku can be encoded as a Boolean satisfiability (SAT) problem (a set of logical clauses that must all be true simultaneously). Modern SAT solvers, which use sophisticated techniques like conflict-driven clause learning (CDCL), can solve sudoku instances along with far harder problems. Encoding sudoku as SAT connects it to one of the most important problems in computer science (SAT was the first problem proven NP-complete, by Stephen Cook in 1971).

Open Questions and Ongoing Research

Several mathematical questions about sudoku remain open or are subjects of active research:

  • Difficulty grading: There is no universally accepted mathematical definition of puzzle difficulty. Current difficulty ratings are based on which human solving techniques are required, but a rigorous mathematical characterization remains elusive.
  • Counting 17-clue puzzles: How many exist in total? McGuire and his co-authors argue that Royle's 49,151 must be almost all of them, but no one has proved the list complete.
  • Symmetry and aesthetics: What is the relationship between a puzzle's symmetry properties and its perceived elegance or solving experience? Puzzle constructors have intuitions about this, but formal mathematical treatment is limited.

These questions ensure that sudoku remains relevant in mathematical research. For a number puzzle that millions of people solve casually every day, its mathematical depth is remarkable, connecting to some of the most fundamental questions in combinatorics, complexity theory, and algorithm design.

Frequently Asked Questions

How many possible sudoku puzzles are there?

There are exactly 6,670,903,752,021,072,936,960 (approximately 6.67 sextillion) valid completed sudoku grids, as computed by Bertram Felgenhauer and Frazer Jarvis in 2005. When accounting for symmetries (relabeling digits, permuting rows/columns, transposing), there are approximately 5.47 billion essentially different grids.

What is the minimum number of clues needed for a valid sudoku?

17 clues is the proven minimum for a sudoku puzzle to have a unique solution. This was proven by Gary McGuire, Bastian Tugemann, and Gilles Civario at University College Dublin in 2012, after approximately 7.1 million core-hours of computation. Gordon Royle's collection lists 49,151 different 17-clue puzzles.

Can a sudoku have 16 clues?

Not with a unique solution. McGuire, Tugemann and Civario searched every essentially different sudoku grid and found no 16-clue set of givens with only one solution, so every 16-clue puzzle has at least two solutions.

What is the difference between a minimum and a minimal sudoku?

The minimum is the fewest clues any proper sudoku can have, which is 17. A minimal sudoku is any puzzle in which every clue is needed, so removing one gives more than one solution. Every 17-clue puzzle is minimal, but minimal puzzles can have 25 or more clues.

Is sudoku NP-complete?

Yes. Takayuki Yato and Takahiro Seta proved in 2003 that the generalized version of sudoku (n²×n² grids with n×n boxes) is NP-complete. This means that while solutions can be verified quickly, no algorithm is known that can solve all instances efficiently. For the standard 9×9 size, solvers work very fast due to the fixed, small size.

Can computers solve sudoku instantly?

Modern algorithms can solve any standard 9×9 sudoku puzzle in milliseconds. Techniques like constraint propagation, backtracking with heuristics, and Donald Knuth's Dancing Links algorithm are all extremely efficient at the 9×9 scale. The NP-completeness of sudoku only matters for generalized, arbitrarily large grids.

Sudoku Royale: classic sudoku, no ads, live matches when you want themDownload Free