Minor refactoring

custom-accumulator
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 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