PS

SUDOKU SOLVER

10 lines of Haskell that solve anything


Solver.hs
1module Solver where
2
3class (Eq c, Show c) => Config c where
4 successors :: c -> [c]
5
6solveAll :: (Config c) => (c -> Bool) -> c -> [c]
7solveAll isGoal c =
8 let rest = concat [solveAll isGoal c' | c' <- successors c]
9 in if isGoal c then c:rest else rest
10
11solve :: (Config c) => (c -> Bool) -> c -> Maybe c
12solve isGoal c = case solveAll isGoal c of
13 [] -> Nothing
14 x:_ -> Just x

click a demo to start

solver@psajnani.com:~$
10 lines. Any problem. Type 'help' or click a demo.
>
speed
slow