Solving Sudoku with Assembly Code
Posted: February 4th, 2009 | Author: YuSuF | Filed under: My Little Projects, Programming | Tags: algorithm, assembly, sudoku | 2 Comments »Who wants to solve the popular sudoku game with assembly code while there are lots of high level languages? Yes, I did. This was one of my home experiment and I wanted to make post about it. Actually assembly code is quite error prone language if you are not careful enough, but with some simple principals and being awake while coding you can create really effective algorithms. The solution does not include backtracking, and able to solve sudokus which don’t require backtrackings.
Here is how the algorithm works;
As you might already know in a sudoku board every cell has 9 possible values from 1 to 9. So while the algorithm traverses the sudoku grid (which is 9×9 matrix) it considers that every single cell has initially 9 possible values, and traverses the 3×3 grid of cell in evaluation and removes the existing values from possibility array. Does the same thing for row and column of the cell. At the and if there is only one possible value it puts the value to the cell, if not continues searching/traversing.
Consider the following example, there are cell that their value is certain. Check the left up most cell of the grid. There is only one possible value which is 2. By the time it puts values to the cells the puzzle gets easier.
And for this board here is the output of the algorithm;
And one last thing to mention; algorithm is assembly function which can be called in from C++ with the help of most compilers;
Here is the code!




