Bad, beginner-Haskell port of Norvig's sudoku solver.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

What is it?

A private learning exercise.

A haskell beginner's attempt to port Peter Norvig's Sudoku solver to Haskell from the original Python found at

Warning: Hazardous!

This is not an example of good Haskell! I do not recommend learning from it.

Better implementations

If you are looking for a good sudoku solver in Haskell, you will find various on the Haskell wiki:

Norvig already links to a haskell implementation of his approach:


(Still here?)

To use it as a library, see:

solve :: String -> Maybe Board
display :: Board -> String

To use it as a stand-alone program:

run the script and feed it puzzle definitions on stdin.

runhaskell Sudoku.hs < top95.txt

Both cases require the same one-puzzle-per-line format as seen in Norvig's write-up.




No attention has been given to performance since porting. Anecdotally, it takes just over 1 second to run the 95 hard problems in the top95.txt input file, on an 4 yr-old laptop.

I haven't tried it on Norvig's identified slow puzzles, but on those it should suffer in the same way his impl does.

About the problem

Sudoku can be understood as a constraint satisfaction problem. A good introductory video is here: