SUDOKU SOLVER Will Bazil, Ryan Covert, Ricky Parker
Abstract ■A Sudoku puzzle is a 9x9 grid composed of 9 rows, 9 columns, and 9 3x3 blocks. ■In order for a Sudoku puzzle to be considered solved each row, column, and block must contain the numbers 1 through 9. ■6,670,903,752,021,072,936,960 possible solutions as calculated by Bertram Felgenhauer and Frazer Jarvis in ■Our goal was to find the most efficient way to solve a Sudoku puzzle.
Formal Definition
Contributions ■James Crook, professor emeritus of Computer Science at Winthrop University, wrote a paper called “A Pencil-and-Paper Algorithm for Solving Sudoku Puzzles” that we based our implementation of Crook’s algorithm on. ■Martin Křivánek wrote his Master Thesis on finding algorithms to determine the difficulty of a puzzle and found that no algorithm is good at predicting the difficulty of a puzzle with accuracy. The metrics used to determine a puzzles difficulty are somewhat ambiguous and there are no rules set in stone.
Algorithms ■Backtracking –An exhaustive algorithm ■Stochastic Search –A type of random algorithm, for example genetic ■Crooks Algorithm –A “pencil and paper” algorithm that can be solved by hand
Benchmarks ■Number of Iterations ■Average Time ■We used five puzzles of each difficulty, easy, medium, and hard, to see how different algorithms performed under different loads.
Graphs For Easy Puzzles
Graphs For Medium Puzzles
Graphs For Hard Puzzles
Graphs For All Puzzles
Conclusions ■EXHAUSTIVE –Always the most expensive for number of iterations. –However, due to the lightweight nature of the individual iterations it was often quite fast, very often the fastest. ■STOCHASTIC –Was a form of genetic algorithm. –Got stuck at local minimums very often, due to the shear number of possibilities and the specificity of Sudoku puzzles. –Due to this, it was always the most time consuming method even though it was often cheaper than the exhaustive in iterations. –Not a very good choice of algorithm for this type of problem. ■CROOKS –Our implementation of Crooks algorithm was by far the cheapest in amount of iterations, solving many easy puzzles in fewer than ten iterations and hard puzzles in as little as fifty iterations. –It was generally comparable in time cost to our exhaustive method but on average slower because Crook’s has to check many more positions of the puzzle per iteration. –Crook’s would easily surpass exhaustive if it was optimized more and coded to recognize more complicated patterns, such as the x wing.
Questions ■What constitutes a Stochastic search? –A Stochastic algorithm is one that finds its solution by using randomly generated variables. ■What algorithms did Křivánek find to be the best at determining the difficulty of a Sudoku puzzle in his research? –None, there are no algorithms that can accurately determine the difficulty of a Sudoku puzzle. This is because there is no standardized metric for determining difficulty. ■What were the best algorithms iteratively, and were they also the fastest? –Crook’s was the best algorithm iteratively, followed by Stochastic. They were not, however, the fastest on average. ■What was Crook’s algorithm mimicking? –The way a human solves a Sudoku puzzle via pencil and paper. ■Why was Crook’s algorithm on average slower than our exhaustive method when it was so good iteratively? –Individual iterations take much longer in Crook’s than in an exhaustive implementation.
Future Work ■Improve our implementation of Crook’s algorithm by optimizing it and introducing more complex techniques, such as x-wings. ■Try other algorithms to get faster results. ■Monitor ongoing efforts to finding a standardized way of determining the difficulty of Sudoku puzzles.