You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
538 B
21 lines
538 B
module Main where
|
|
|
|
main :: IO()
|
|
main = interact solution
|
|
|
|
solution :: String -> String
|
|
solution = show
|
|
. multhem
|
|
. foldl applymove (0, 0)
|
|
. map ((\[a, b] -> (head a, read b :: Int)) . words)
|
|
. lines
|
|
where
|
|
applymove :: (Int, Int) -> (Char, Int) -> (Int, Int)
|
|
applymove (x, y) (d, v) = case d of
|
|
'f' -> (x + v, y)
|
|
'd' -> (x, y + v)
|
|
'u' -> (x, y - v)
|
|
_ -> undefined -- unreachable
|
|
multhem :: (Int, Int) -> Int
|
|
multhem (a, b) = a * b
|
|
|