From 9c77daf53902b96775688efd5a42f15096184fa3 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sun, 6 Dec 2020 07:36:45 +0100 Subject: [PATCH] haskell: don't force concatenation in splitOnEmptyLines --- 2020/day4/day4.hs | 2 +- common/AoC.hs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/2020/day4/day4.hs b/2020/day4/day4.hs index fd643af..e219db0 100644 --- a/2020/day4/day4.hs +++ b/2020/day4/day4.hs @@ -93,4 +93,4 @@ hasAllRequiredFields = maybe False containsAllFields . fieldNames containsAllFields fields = all (`elem` fields) requiredFieldNames 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)) diff --git a/common/AoC.hs b/common/AoC.hs index cd4fa64..d457242 100644 --- a/common/AoC.hs +++ b/common/AoC.hs @@ -13,8 +13,8 @@ oneCompleteResult p s = case readP_to_S (p <* eof) s of [(x, "")] -> Just x _ -> Nothing -splitOnEmptyLines :: String -> [String] -splitOnEmptyLines = map (intercalate " ") . filter (not . any null) . groupBy ((==) `on` null) . lines +splitOnEmptyLines :: String -> [[String]] +splitOnEmptyLines = filter (not . any null) . groupBy ((==) `on` null) . lines runAoC :: (Show r1, Show r2) => (String -> i) -> (i -> r1) -> (i -> r2) -> IO () runAoC inputTransform part1 part2 = do