From c5aa52cb73edb3e646d706fb19e09e7fed6a6a86 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 --- day3/day3.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/day3/day3.hs b/day3/day3.hs index 5d9cb30..53dfa13 100644 --- a/day3/day3.hs +++ b/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 = (== '#')