Studieren Sie das Aufgaben-Papier zu Sudoku und lösen Sie die dort enthaltenen Aufgaben.
> module Sudoku where
> import Data.Char
> import Data.List
> type Sudoku a = [[a]]
> type Options= [Int]
> type SudokuPuzzle = Sudoku Options
> unsovable :: SudokuPuzzle -> Bool
> unsovable = or.map (elem [])
> sc4 =
> "....6..8.\n\
> \.2.......\n\
> \..1......\n\
> \.7....1.2\n\
> \5...3....\n\
> \......4..\n\
> \..42.1...\n\
> \3..7..6..\n\
> \.......5."
> readSudoku :: String -> SudokuPuzzle
> readSudoku xs = []
> toLaTeX :: SudokuPuzzle -> String
> toLaTeX xss = ""
> columns, rows :: Sudoku a -> Sudoku a
> rows = id
> columns = transpose
> boxes :: Sudoku a -> Sudoku a
> boxes xss = xss
> correct:: Eq a => [a]->Bool
> correct xs = 9 == length (nub xs)
> solved xss = okay (rows xss) && okay (columns xss) && okay (boxes xss)
> where okay = and.(map correct)
> limitLine:: [Options] -> [Options]
> limitLine lss = lss
> limitation :: SudokuPuzzle -> SudokuPuzzle
> limitation
> = boxes
> .map limitLine.boxes
> .map limitLine.columns
> .map limitLine.rows
> versions :: SudokuPuzzle -> Integer
> versions = (product.map (toInteger.length).concat)
> limitations lls
> |versions lls' == versions lls = lls
> |otherwise = limitations lls'
> where
> lls' = limitation lls
> sc3 =
> ".26...81.\n\
> \3..7.8..6\n\
> \4...5...7\n\
> \.5.1.7.9.\n\
> \..39.51..\n\
> \.4.3.2.5.\n\
> \1...3...2\n\
> \5..2.4..9\n\
> \.38...46."
> firstFillings :: SudokuPuzzle -> [SudokuPuzzle]
> firstFillings xss = []
> solve xs
> |vs==0 = []
> |vs==1 && solved lxs = [lxs]
> |otherwise = concat$map solve$firstFillings lxs
> where
> lxs = limitations xs
> vs = versions lxs
> sc2 =
> "8156....4\n\
> \6...75.8.\n\
> \....9....\n\
> \9...417..\n\
> \.4.....2.\n\
> \..623...8\n\
> \....5....\n\
> \.5.91...6\n\
> \1....7895";
> sc5 =
> ".5..6...1\n\
> \..48...7.\n\
> \8......52\n\
> \2...57.3.\n\
> \.........\n\
> \.3.69...5\n\
> \79......8\n\
> \.1...65..\n\
> \5...3..6."
> moin = do
> print $solve $readSudoku sc2
> print $solve $readSudoku sc3
> print $solve $readSudoku sc4
> print $solve $readSudoku sc5