Using only list comprehensions:
type Matrix a = [[a]]
type Grid = Matrix Int
choicesComp :: Grid -> Matrix [Int]
choicesComp rows =
[[[d | d <- [1..9], n == 0 || d == n] | n <- row] | row <- rows]The input contract restricts each cell to zero or a digit from one to nine. A definition using standard list functions is:
choicesMap :: Grid -> Matrix [Int]
choicesMap = map (map choice)
where
choice :: Int -> [Int]
choice 0 = [1..9]
choice n = [n]
choices :: Grid -> Matrix [Int]
choices = choicesMapBoth preserve the row structure and construct the initial constraint domains of the Sudoku problem. The alternative names let both definitions coexist; either can supply
choices. Articles by others on the same topic
There are currently no matching articles.