Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Paren = Open
- | Close
- deriving Show
- toParenList :: String -> Maybe [Paren]
- toParenList [] = Just []
- toParenList (x:xs) = case x of
- '(' -> fmap (Open:) (toParenList xs)
- ')' -> fmap (Close:) (toParenList xs)
- _ -> Nothing
- floors :: [Paren] -> [Int]
- floors = scanl (\acc y -> case y of
- Open -> acc + 1
- Close -> acc - 1
- ) 0
- f3 :: String -> Maybe [Int]
- f3 = toParenList >=> pure . floors
- floorEnds :: String -> Maybe Int
- floorEnds input2 = case f3 input2 of
- Just x -> Just $ last x
- Nothing -> Nothing
- whenEntersBasement :: String -> Maybe Int
- whenEntersBasement input2 = case f3 input2 of
- Just x -> elemIndex (-1) x
- Nothing -> Nothing
- main' = fromMaybe "Invalid input" . fmap show . whenEntersBasement <$> readFile "input.txt"
Add Comment
Please, Sign In to add comment