haskell: don't force concatenation in splitOnEmptyLines
This commit is contained in:
parent
4f13a47281
commit
b1ac705f73
2 changed files with 3 additions and 3 deletions
|
@ -13,8 +13,8 @@ oneCompleteResult p s = case readP_to_S (p <* eof) s of
|
||||||
[(x, "")] -> Just x
|
[(x, "")] -> Just x
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
splitOnEmptyLines :: String -> [String]
|
splitOnEmptyLines :: String -> [[String]]
|
||||||
splitOnEmptyLines = map (intercalate " ") . filter (not . any null) . groupBy ((==) `on` null) . lines
|
splitOnEmptyLines = filter (not . any null) . groupBy ((==) `on` null) . lines
|
||||||
|
|
||||||
runAoC :: (Show r1, Show r2) => (String -> i) -> (i -> r1) -> (i -> r2) -> IO ()
|
runAoC :: (Show r1, Show r2) => (String -> i) -> (i -> r1) -> (i -> r2) -> IO ()
|
||||||
runAoC inputTransform part1 part2 = do
|
runAoC inputTransform part1 part2 = do
|
||||||
|
|
|
@ -93,4 +93,4 @@ hasAllRequiredFields = maybe False containsAllFields . fieldNames
|
||||||
containsAllFields fields = all (`elem` fields) requiredFieldNames
|
containsAllFields fields = all (`elem` fields) requiredFieldNames
|
||||||
fieldNames = oneCompleteResult parseFieldNames
|
fieldNames = oneCompleteResult parseFieldNames
|
||||||
|
|
||||||
main = runAoC (filter hasAllRequiredFields . splitOnEmptyLines) (length) (length . mapMaybe (oneCompleteResult parsePassport))
|
main = runAoC (filter hasAllRequiredFields . map (intercalate " ") . splitOnEmptyLines) (length) (length . mapMaybe (oneCompleteResult parsePassport))
|
||||||
|
|
Loading…
Reference in a new issue