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