Simple Sudoku Solver

  • Category: PC/C++ prototype
  • Project date: May, 2021
  • Git Repository: GitLab

THE REASON

After taking some courses for C ++ (you can check them out here) I decided to do some practice on my own.

While following a tutorial everything seems clear and obvious to you, but when you try to create something from scratch ... difficulties arise!

So after I made a Pong game with C++ to practice and to get more comfortable with C++, I tried to make something with more complex logic. I started to make a Sudoku Solver, then I realize the complexity of such task and it became a "Simple Sudoku Solver", with the hope that it will be "Sudoku Solver" again in the future. That's why it can only solve simple sudoku at the moment (due of the simple logic I implemented so far).



THE LOGIC

After I read the matrix of the sudoku and populated my data structure, the logic I implemented is very simple:

  • I loop through each cell, creating a list with the digits that are missing at the same time on that row, column and region (so they are the possible digits for that cell).
  • If a list has only one element, it means it's the only digit it can fit there. So it is placed into the cell, and since we can exclude it from the entire row, column and region, it's removed from their missing list (or the possible digits).
  • Placing a digit will reduce the missing digits for the other lists, hopefully causing a few of them to reach one element, so we can place another digit and go on until the sudoku it's completed.

  • Of course, this is not an exhaustive solution, since it can happen that no list reach one element, but as I said, this is the first step towards a sudoku solver that can handle each type of difficulty (that are valid, of course).