Minor refactoring
This commit is contained in:
parent
b2a0dd8817
commit
30ebffa1b5
|
@ -13,9 +13,10 @@ possibleVals (Fixed x) = [x]
|
|||
possibleVals (Possible xs) = xs
|
||||
|
||||
readGrid :: String -> Maybe Grid
|
||||
readGrid s = if length s /= 81
|
||||
then Nothing
|
||||
else sequence . map (sequence . map readCell) . Data.List.Split.chunksOf 9 $ s
|
||||
readGrid s
|
||||
| length s == 81 =
|
||||
sequence . map (sequence . map readCell) . Data.List.Split.chunksOf 9 $ s
|
||||
| otherwise = Nothing
|
||||
where
|
||||
readCell '.' = Just $ Possible [1..9]
|
||||
readCell c
|
||||
|
@ -33,7 +34,9 @@ showGridWithPossibilities = unlines . map (unwords . map showCell)
|
|||
where
|
||||
showCell (Fixed x) = show x ++ " "
|
||||
showCell (Possible xs) =
|
||||
(Data.List.foldl' (\acc x -> acc ++ if x `elem` xs then show x else " ") "[" [1..9]) ++ "]"
|
||||
(++ "]")
|
||||
. Data.List.foldl' (\acc x -> acc ++ if x `elem` xs then show x else " ") "["
|
||||
$ [1..9]
|
||||
|
||||
|
||||
main = undefined
|
Loading…
Reference in New Issue