day3/haskell: make it more readable

This commit is contained in:
Xiretza 2020-12-04 10:34:46 +01:00
parent faaaaec0ff
commit c5aa52cb73
Signed by: xiretza
GPG key ID: 17B78226F7139993

View file

@ -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 = (== '#')