


However, for proper Sudokus, linear programming presolve techniques alone will deduce the solution without any need for simplex iterations. If there is more than one solution (non-proper Sudokus) the simplex algorithm will generally yield a solution with fractional amounts of more than one digit in some squares.

The simplex algorithm is able to solve proper Sudokus, indicating if the Sudoku is not valid (no solution). Such approaches get close to a solution quickly, and can then use branching towards the end. It is also possible to express a Sudoku as an integer linear programming problem. Algorithms designed for graph colouring are also known to perform well with Sudokus. Unlike the latter however, optimisation algorithms do not necessarily require problems to be logic-solvable, giving them the potential to solve a wider range of problems. Stochastic-based algorithms are known to be fast, though perhaps not as fast as deductive techniques. Approaches for shuffling the numbers include simulated annealing, genetic algorithm and tabu search. "Shuffle" the inserted numbers until the number of mistakes is reduced to zero.Ī solution to the puzzle is then found.Randomly assign numbers to the blank cells in the grid.Sudoku can be solved using stochastic (random-based) algorithms. Such a Sudoku can be solved nowadays in less than 1 second using an exhaustive search routine and faster processors. In one case, a programmer found a brute force program required six hours to arrive at the solution for such a Sudoku (albeit using a 2008-era computer). Thus the program would spend significant time "counting" upward before it arrives at the grid which satisfies the puzzle. Assuming the solver works from top to bottom (as in the animation), a puzzle with few clues (17), no clues in the top row, and has a solution "987654321" for the first row, would work in opposition to the algorithm. One programmer reported that such an algorithm may typically require as few as 15,000 cycles, or as many as 900,000 cycles to solve a Sudoku, each cycle being the change in position of a "pointer" as it moves through the cells of a Sudoku.Ī Sudoku can be constructed to work against backtracking. The disadvantage of this method is that the solving time may be slow compared to algorithms modeled after deductive methods. The algorithm (and therefore the program code) is simpler than other algorithms, especially compared to strong algorithms that ensure a solution to the most difficult puzzles.Solving time is mostly unrelated to degree of difficulty.A solution is guaranteed (as long as the puzzle is valid).Notice that the algorithm may discard all the previously tested values if it finds the existing set does not fulfil the constraints of the Sudoku. The puzzle's clues (red numbers) remain fixed while the algorithm tests each unsolved cell with a possible solution. The animation shows how a Sudoku is solved with this method. This is repeated until the allowed value in the last (81st) cell is discovered. The value in that cell is then incremented by one. If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. When checking for violations, if it is discovered that the "1" is not allowed, the value is advanced to "2". If there are no violations (checking row, column, and box constraints) then the algorithm advances to the next cell and places a "1" in that cell. Briefly, a program would solve a puzzle by placing the digit "1" in the first cell and checking if it is allowed to be there. A brute force algorithm visits the empty cells in some order, filling in digits sequentially, or backtracking when the number is found to be not valid.
