sbv-5.7: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.

Copyright(c) Levent Erkok
Safe HaskellNone




The Sudoku solver, quintessential SMT solver example!


Modeling Sudoku

type Row = [SWord8] Source

A row is a sequence of 8-bit words, too large indeed for representing 1-9, but does not harm

type Board = [Row] Source

A Sudoku board is a sequence of 9 rows

check :: [SWord8] -> SBool Source

Given a series of elements, make sure they are all different and they all are numbers between 1 and 9

valid :: Board -> SBool Source

Given a full Sudoku board, check that it is valid

type Puzzle = (Int, [SWord8] -> Board) Source

A puzzle is a pair: First is the number of missing elements, second is a function that given that many elements returns the final board.

Solving Sudoku puzzles

sudoku :: Puzzle -> IO () Source

Solve a given puzzle and print the results

dispSolution :: Puzzle -> (Bool, [Word8]) -> IO () Source

Helper function to display results nicely, not really needed, but helps presentation

solveAll :: Puzzle -> IO () Source

Find all solutions to a puzzle

Example boards

puzzle0 :: Puzzle Source

Find an arbitrary good board

puzzle1 :: Puzzle Source

A random puzzle, found on the internet..

puzzle2 :: Puzzle Source

Another random puzzle, found on the internet..

puzzle3 :: Puzzle Source

Another random puzzle, found on the internet..

puzzle4 :: Puzzle Source

According to the web, this is the toughest sudoku puzzle ever.. It even has a name: Al Escargot:

puzzle5 :: Puzzle Source

This one has been called diabolical, apparently

puzzle6 :: Puzzle Source

The following is nefarious according to

allPuzzles :: IO () Source

Solve them all, this takes a fraction of a second to run for each case