The Math Behind Sudoku: How to Solve Sudoku Mathematically

There are many ways to solve Sudoku puzzles. 

Some strategies involve looking for hidden pairs or triples, or naked pairs or triples. Other strategies involve looking for patterns such as X-Wings and Y-Wings

And of course, the most basic strategy is to go through empty cells to see which numbers fit and trying to find cells where there is only one possible candidate. 

Point is, despite Sudoku being a number puzzle, there are many ways to solve Sudokus without needing any math or arithmetic. 

In fact, you could replace the numbers 1 to 9 with some other kind of symbol, such as letters, or even colors, and the fundamental logic of the Sudoku rules would still apply. 

But, where there are numbers, there is math. And there’s plenty of math you can perform with Sudoku. You can potentially even solve Sudoku with math. 

So let’s take a look at the math behind Sudoku. 

The mathematics of Sudoku

Sudoku rules

First, let’s recap the basic rules of Sudoku. 

A Sudoku puzzle consists of a 9×9 grid of 81 cells subdivided into nine 3×3 boxes. The digits 1 to 9 must be placed in these 81 cells so that no digit can repeat in any 3×3 box or any of the 9-cell rows or columns in the grid. 

Despite a popular misconception, there is no diagonal rule requiring the two 9-cell diagonals to also the digits 1 to 9 once each. 

Depending on the difficulty of the puzzle, a certain number of the 81 cells will already have given digits in them to ensure the puzzle has a unique solution and that you are able to complete the puzzle. 

Basic math

From this basic rule set, some math immediately arises. 

Because every row, column, and box must contain the digits 1 to 9, it also means these areas will always sum to 45. This is known as the rule of 45

This is fairly straightforward, however, it can be helpful in solving puzzles, especially Sudoku variants where the sum of digits matter such as in Killer Sudoku and Sandwich Sudoku.

Some less immediately obvious math that emerges from the basic rule set is that there are 6,670,903,752,021,072,936,960 unique possible Sudoku grids. That’s 6.67×1021

Minimum number of givens

Because every regular Sudoku puzzle contains a unique solution, a minimal Sudoku is a puzzle that contains the fewest number of given digits to ensure it maintains a unique solution. 

In other words, if you remove even one given digit, the puzzle will no longer have a unique solution. 

A computer science paper by Gary McGuire, Bastian Tugemann, and Gilles Civario found that the minimum number of givens possible for a unique puzzle is 17. 

That is, in terms of regular Sudoku, it is not possible for a puzzle to contain 16 or fewer digits and still have a unique solution. 

So far, the largest minimum Sudoku contains 40 given digits. That is, because of the way the given digits are arranged, it is not possible to remove even one of the 40 given digits without creating multiple solutions for the puzzle. 

Symmetry

In terms of Sudoku puzzles, symmetry simply refers to how the given digits are arranged in the puzzle. 

There are three types of symmetry that can occur in a Sudoku puzzle: point, line, and rotational. 

Point symmetry is when the given cells in a Sudoku grid are arranged such that if you were to draw a line through the center of the grid, each half would be a reflection of the other. In other words, it would look symmetrical about a central point. 

Line symmetry is when the given cells in a Sudoku grid are arranged such that if you were to draw a line through the center of the grid, each half would be an identical copy of the other. In other words, it would look symmetrical about a central line. 

Rotational symmetry is when the given cells in a Sudoku grid are arranged such that if you were to rotate the grid by some angle, it would look identical to the original grid. 

The vast majority of Sudoku puzzles have no symmetry or only point symmetry. However, there are some puzzles that have line symmetry or rotational symmetry. 

How to solve a sudoku puzzle mathematically

Now that we’ve looked at the mathematics of Sudoku, let’s consider how you can solve Sudoku with math. 

There are a few different approaches you can take, but we’ll focus on what’s known as the Dancing Links algorithm. 

The basic idea behind the Dancing Links algorithm is to construct a matrix that represents all the possible ways to fill in a Sudoku grid such that every row, column, and box contains the digits 1 to 9. 

From this matrix, you can then use a technique called backtracking to systematically find the unique solution to the puzzle. 

If you’re interested in learning more about how the Dancing Links algorithm works, check out this more detailed explanation.