Minor refactoring

This commit is contained in:
Abhinav Sarkar 2018-06-17 11:54:22 +05:30
parent b2a0dd8817
commit 30ebffa1b5
1 changed files with 7 additions and 4 deletions

View File

@ -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