This is a java implementation of a Sudoku solver which was initially posted to me as a java exercise question from my IS200 IS Foundations course. I'm posting this up for the fun of it.
Currently a brute-force, backtracking (BFBT) algorithm is used to solve the puzzle and is inefficient at puzzles with minimal hints. One of the highest-difficulty puzzle currently takes approximately 1000 milliseconds under this algorithm.
This solver takes in 81 arguments, one for each cell, separated by a space, as the initial puzzle state.
$ java SudokuSolver \
0 6 3 4 9 0 0 0 1 \
0 0 0 0 0 0 7 0 9 \
0 1 9 0 0 0 0 0 0 \
0 0 1 0 0 2 9 3 0 \
9 0 0 1 0 7 0 0 2 \
0 7 8 9 0 0 4 0 0 \
0 0 0 0 0 0 8 2 0 \
3 0 6 0 0 0 0 0 0 \
4 0 0 0 2 9 1 7 0
There are plans to implement the following:
- Improve the current brute-force, backtracking (BFBT) algorithm by iterating through a list of valid numbers in random order, rather than just blindly going through 1–9.
- Supersede the current BFBT algorithm with Dancing Links (DLX), keeping BFBT as an option.
All suggestions on improving efficiency, or coding improvements, are welcome via pull requests.