Solving Sudoku with Assembly Code

Yusuf Erdo
Think out of the net
2 min readFeb 3, 2009

Follow me for more of this kind of posts: https://twitter.com/erdogany

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 experiments and I wanted to make a post about it. Actually, assembly code is quite an error-prone language if you are not careful enough, but with some simple principles and being awake while coding you can create really effective algorithms. The solution does not include backtracking and is able to solve sudokus which don’t require backtracking.

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 a 9x9 matrix) it considers that every single cell has initially 9 possible values, traverses the 3x3 grid of cell in the evaluation and removes the existing values from the possibility array. Does the same thing for the 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 cells whose values are certain. Check the left up the 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; the algorithm is an assembly function that can be called in from C++ with the help of most compilers;

You can find the code in GitHub:
https://github.com/erdogany/SudokuSolverAssembly
https://github.com/erdogany/SudokuSolverAssembly.git

--

--

Yusuf Erdo
Think out of the net

Writing about #genai #llm #openai #typescript #graphql #serverless #lambda #dynamodb #elasticsearch