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
1 changed files with 7 additions and 1 deletions

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