An NP-complete problem satisfies the following two properties:
This places the game of solving rank-n Sudoku puzzles in a class of problems that computer scientists have named NP-complete. As the rank of a Sudoku increases from n to n+1, the extra computational time needed to find a solution increases quite fast. Find two different solutions.įor 4×4 Sudoku, a case-by-case analysis utilizing the two essentially different grids proves that a well-formed puzzle must have a minimum of four distinct digits in the givens.įinally, it is intriguing to note that even though there are computer programs that can quickly and easily solve rank-3 Sudokus by employing a backtracking method, solving a Sudoku of arbitrary rank n is a much more difficult problem. The next exercise illustrates this with a specific example.Įxercise: The following rank-2 Sudoku has 2 2-1=3 distinct digits among the givens. Recall that the converse of a true statement is not necessarily true. It is important to note that this is not the same as stating that if a Sudoku of rank n has n 2-1 distinct digits in the givens, then it is well-formed. The fact discussed above can be restated as follows: If a Sudoku of rank n is well-formed, then it must have n 2-1 distinct digits among the givens. In particular, for the usual rank-3 Sudoku, at least 3 2-1=8 distinct digits must be used in the givens for the puzzle to be well-formed otherwise, the puzzle will have more than one solution. This is because if we had a rank-n puzzle where only n 2-2 symbols were used and we found a solution, then interchanging the places of the two symbols missing from the givens would result in another, different solution. However, the minimum number of givens for which a rank-3 Sudoku can be well-formed is not known.Įxercise: Can you come up with a Sudoku puzzle that is not well-formed?Īnother interesting question (that you may have considered when solving the above exercise) is how many distinct symbols need to be used among the givens for a puzzle to be well-formed? It turns out that for a Sudoku of rank n, at least n 2-1 distinct symbols must be used for the puzzle to have a unique solution. There are examples of rank-3 Sudoku puzzles with 17 givens that are well-formed.
A Sudoku puzzle can have more than one solution, but in this case the kind of logical reasoning we described while discussing solving strategies may fall short. Z = find(X(:) = 0,1) % The first unfilled cell.įor r = % Iterate over candidates.The Math Behind Sudoku Some More Interesting FactsĪ well-formed Sudoku puzzle is one that has a unique solution. % e is the first cell, if any, with no candidates. % s is the first cell, if any, with one candidate. % C is a cell array of candidate vectors for each cell. % SUDOKU Solve Sudoku using recursive backtracking. The only way that I know to check for uniqueness is to exhaustively enumerate all possible solutions. Some of the puzzle-generating programs on MATLAB Central do not check uniqueness.
Again, it would be frustrating to discover a solution different from the one given. Most descriptions of Sudoku do not specify that there must be only one solution. Our program terminates the recursion when it encounters a cell that has no candidates. It would be very frustrating if such a puzzle were to show up in your newspaper.īacktracking generates many impossible configurations. For example, with the puzzle shown in Figure 1, if we were to insert a “1”, “5,” or “7” in the (1,1) cell, the row, column, and block conditions would be satisfied but the resulting puzzle would have no solution. With Sudoku, neither existence nor uniqueness can easily be determined from the initial clues. As mathematicians, we seek to prove that a solution to a problem exists, and that it is unique.