```board = [0,3,4,1,7,0,5,0,0,
0,6,0,0,0,8,3,0,1,
7,0,0,3,0,0,0,0,6,
5,0,0,6,4,0,8,0,7,
0,1,0,9,0,0,0,6,0,
3,0,6,0,0,2,0,0,4,
8,0,0,0,0,9,0,0,2,
1,0,3,7,0,0,0,9,0,
0,0,9,0,3,1,7,4,0]

nodup x = (length y) == (length \$ nub y) where y = filter (/=0) x
boardlen = round.sqrt.fromIntegral \$ length board
pointnum bd answernum = length.last.filter (\x->sum x == answernum) \$ inits \$ map (\x -> if x /= 0 then 0 else 1) bd

newboard (0:xs) (y:ys) = y:newboard xs ys
newboard (x:xs) s      = x:newboard xs s
newboard s []          = s

pointcheck (row, col) bd = all nodup [map (\x->bd!!(row*9+x)) [0..8], map (\x->bd!!(x*9+col)) [0..8], smallgrid bd] where
rowmin = row `div` 3 * 3
colmin = col `div` 3 * 3
smallgrid bd = [bd !! (row*9+col) | row <- [rowmin..(rowmin+2)], col <- [colmin..(colmin+2)]]

point = pointnum board \$ length answer
(row, col) = divMod point boardlen

sudokuIterate = iterate (concatMap \$ nextanswer) [[]]

divide bd = unfoldr (\x -> if x == [] then Nothing else Just (splitAt 9 x)) bd

sudoku = mapM_ (\x -> sequence [putStrLn "answer:", mapM_ print (divide \$ newboard board x), putStrLn ""])
\$ sudokuIterate !! length (filter (== 0) board)

main = sudoku```

```*Main> :l algorithm.hs
[1 of 1] Compiling Main             ( algorithm.hs, interpreted )
*Main> sudoku
[2,3,4,1,7,6,5,8,9]
[9,6,5,4,2,8,3,7,1]
[7,8,1,3,9,5,4,2,6]
[5,9,2,6,4,3,8,1,7]
[4,1,8,9,5,7,2,6,3]
[3,7,6,8,1,2,9,5,4]
[8,4,7,5,6,9,1,3,2]
[1,2,3,7,8,4,6,9,5]
[6,5,9,2,3,1,7,4,8]```

• 0

开心

• 0

板砖

• 0

感动

• 0

有用

• 0

疑问

• 0

难过

• 0

无聊

• 0

震惊