From 793eefc817491e91322155bd3f3b3166a6cc98d9 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Fri, 4 Dec 2020 10:34:46 +0100 Subject: [PATCH] day3/haskell: make it more readable --- 2020/day3/day3.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/2020/day3/day3.hs b/2020/day3/day3.hs index 5d9cb30..53dfa13 100644 --- a/2020/day3/day3.hs +++ b/2020/day3/day3.hs @@ -11,7 +11,13 @@ f .: g = (f .) . g infixl 8 .: countHits :: (Int, Int) -> [[Bool]] -> Int -countHits = length . filter id . map (uncurry $ flip (!!)) . catMaybes .: compose2 (zipWith mzip) (uncurry . flip $ compose2 intercalate (flip replicate empty . pred) (fmap pure . map pure . enumFromThen 0)) (map pure) +countHits = length . filterMap lookup . catMaybes .: compose2 (zipWith mzip) maybeIndices justLines + where justRightSteps = map (pure . Just) . enumFromThen 0 + downNothings = flip replicate Nothing . pred + maybeIndices = uncurry $ compose2 (flip intercalate) justRightSteps downNothings + justLines = map Just + lookup = uncurry $ flip (!!) + filterMap = filter id .: map treeCharToBool :: Char -> Bool treeCharToBool = (== '#')