A Sudoku solver in Go.
The puzzles are solved using constraint propagation and backtracking search, using an algorithm that's pretty similar to Peter Norvig's solver.
This was mostly an excuse to learn Go and play with its concurrency features. Both sequential and parallel implementations are included. They both use the same algorithm, but the parallel version takes advantage of multi-core CPUs.
There are 3 variants of the solvers. Make sure to set your GOPATH
before running.
$ export GOPATH=$PWD
$ go run sudoku.go puzzles/p1
$ go run sudoku_sequential.go sets/hard.gz
$ go run sudoku_parallel.go sets/hard.gz
Some example puzzles are included in the puzzles/
and sets/
directories.
These are in 9x9 format, where periods (.
) represent blank cells. Whitespace is
ignored.
1..6..2..
.6.2.4...
..2...8.3
75...8.1.
....1....
.4.3...56
2.4...1..
...5.3.4.
..3..9..7
These can be solved with the single puzzle solver: sudoku
These are gzip'd text files where each 81-character line is a separate puzzle.
1..6..2...6.2.4.....2...8.375...8.1.....1.....4.3...562.4...1.....5.3.4...3..9..7
These can be solved with either of the batch solvers: sudoku_sequential or sudoku_parallel