Sudoku Solver Algorithm

909 Words2 Pages

Sudoku puzzles are created with the intent of being solved by human players with pencil, however as with many things they can be solved much faster with computers. The layout of a Sudoku puzzle comprises of nine rows and nine columns which make up eighty-one total squares. Sudoku puzzles have nine non- overlying zones each consisting of three grid rows and three grid columns, or nine total grids. In each of these zones all of the numbers must be unique (numbered one-nine). On a similar note, each number in a row or column must be unique (one-nine) . Players must use deduction and reasoning to solve these puzzles without making a mistake to arrive at the solution.
The Algorithm

Solver is an algorithm that does precisely what its name implies, it solves Sudoku puzzles. The goal is to provide the solution to the puzzle with the given inputs. Since every Sudoku puzzle only has one solution , there is no need for the solver to attempt to find multiple solutions.

Input and Output
Solver receives the Sudoku puzzle as input, which is given as a nine by nine two dimensional array. Prior to any solving the algorithm first checks if the input is valid. To do this it first makes sure that it receives a nine by nine two dimensional array by running it through a nested for loop making sure there are the right number of cells. It then checks to make sure there are no row, column, or block violations (such as there being more than 2 of the same number in a row, column or block). In addition to this it also does not allow you to input any number larger than nine. The way it does this is to only allow input of zero through nine, if the input does not satisfy this condition then the input is replaced with a white space. After the solving is d...

... middle of paper ...

... be informed of this and may not notice the change to whitespace. This could be a potential problem if the user does not notice before he/she presses to solve it, which would cause the solver algorithm would not give the solution that the user had wanted.
Summary

The Sudoku solver is an algorithm that gets the input of a Sudoku puzzle and attempts to solve it, returning a completely full Sudoku puzzle as a two dimensional matrix. Based upon a brute force algorithm it is not the most efficient algorithm, however it does get the job done. The addition of the options vector is an attempt to optimize the standard brute force method and greatly simplifies the algorithm. While the algorithm is not the most efficient, the fact that the input size is always the same (a nine by nine matrix) and is not particularly large, the inefficiency of the algorithm is not too taxing.

Open Document