Sudoku Solver

I created a Sudoku Solver. You can view the app here.

There are a few important aspects of the program I thought it would be useful to talk about. These are the general process of solving a board, as well as the process of creating a board to be solved.

Solving a Sudoku 🔗︎

The method that I used in this case is the backtracking method .

Sudoku is a very good game to demonstrate this algorithm. When you play sudoku, you often run into the situation where a cell may contain more than one possible value. This is a problem, and is solved by backtracking. In this situation, the algorithm will place one of the possibilities in the cell, and continue to solve the sudoku. When it reaches a contradictory position, it will walk back to one of these situations with multiple possibilities, choose the next possibility and continue.

This process repeats until all the cells of the sudoku are filled.

Further reading: https://www.101computing.net/backtracking-algorithm-sudoku-solver/

Creating a Sudoku Problem 🔗︎

Another problem I came across is that of creating a sudoku to be solved. I found that there are many different ways to do this, but I have chosen a fairly simple method.

Switching rows and columns will not affect the ability to find a solution of the sudoku. However this only occurs if you switch rows and columns in each set of 3, for example switching rows 1-3, 4-6 and 7-9. These rows and columns can be randomly switched to generate a problem.

First a sudoku is solved, in my case I just solve an empty sudoku. Next the rows and columns in each group of 3 are switched randomly to create a new solution. The final step is to pick n different numbers to be displayed as the problem. This creates a valid and likely unique starting sudoku for the person to solve.

Other methods can include testing for a unique board, and taking the solution where there is only one possible solution, rather than many. This method can create situations where if one number was taken from the board, the sudoku would be unsolvable.

I found this link to be very helpful: https://stackoverflow.com/questions/6924216/how-to-generate-sudoku-boards-with-unique-solutions/7280517

There are many different possibilities with sudoku! I hope you learned something from my post.