Sudoku Puzzle Solver using a back tracking approach.
I recently came across several articles (medium.com) describing how to create a solver for Sudoku using Python.
One article took a Linear Optimization/Programming approach. Using linear programming for a problem like Sudoku is tremendous overkill. However, Sudoku provided an excellent easy-to-grasp problem for introducing Linear Optimization concepts; something the author put to good use.
There were articles using Neural Nets (a poorer match), search type approaches, and some pretty raw back tracking.
Sudoku is not a "hard" problem. However, due to its potential graph complexity it can become quite difficult to work through manually.
This project is a single JS file (for now anyways) which will:
- create a Sudoku Game (puzzle) based on an array of integers passed to it
- solve the puzzle
- print the unsolved and solved forms of the puzzle
- print basic statistics generated while solving
It turned out to be a good bit simpler than I anticipated. The code (other than the print functions) is decent, not great but decent.
The code is vanilla Javascript though assumes it's run from nodejs, node sudoku-solver.js
as it relies on the node perf libs when gathering stats.
One will see the use of: row
and col
in the code.
The code does not implement a table structure, much less one composed of Rowa and Columns.
Rather, row
and col
are mere syntactic sugar. They represent X and Y coordinates respectively; coordinates of the matrix used to internally represent the puzzle.
Put more directly, they are used to represent a row index
or a col [column] index