module Main where main :: IO () main = interact solution solution :: String -> String solution = show . multhem . foldl applymove (0, 0, 0) . map ((\[a, b] -> (head a, read b :: Int)) . words) . lines where applymove :: (Int, Int, Int) -> (Char, Int) -> (Int, Int, Int) applymove (x, y, a) (d, v) = case d of 'f' -> (x + v, y + v * a, a) 'd' -> (x, y, a + v) 'u' -> (x, y, a - v) _ -> undefined -- unreachable multhem :: (Int, Int, Int) -> Int multhem (a, b, _) = a * b