module Main where import Debug.Trace (trace) convertToInts = map (\it -> (if head it == 'L' then -1 else 1) * read (drop 1 it)) part1 :: String -> Int part1 = length . dropNonZero . scanl (+) 50 . convertToInts . lines where dropNonZero = filter ((0==) . (`mod` 100)) part2 :: String -> Int part2 = go 50 . convertToInts . lines where go :: Int -> [Int] -> Int go p [] = 0 go p (x:xs) = n + edgeCase + go p' xs where n = abs $ p' `div` 100 - p `div` 100 edgeCase = if x < 0 && p' `mod` 100 == 0 then 1 else 0 + if x < 0 && p `mod` 100 == 0 then -1 else 0 p' = (p + x) main :: IO () main = do str <- getContents print $ part1 str print $ part2 str