day3/haskell: make it more readable

This commit is contained in:
Xiretza 2020-12-04 10:34:46 +01:00
parent eecf2c2f35
commit 793eefc817

View file

@ -11,7 +11,13 @@ f .: g = (f .) . g
infixl 8 .: infixl 8 .:
countHits :: (Int, Int) -> [[Bool]] -> Int 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 :: Char -> Bool
treeCharToBool = (== '#') treeCharToBool = (== '#')