import System.IO main = do file <- readFile "../input/02" let (x, y) = foldl step (0, 0) $ map parse $ lines file print (x, y, x * y) parse s = case name of "up" -> Up n "down" -> Down n "forward" -> Forward n where [name, x] = words s n = read $ x parse :: String -> Action data Action = Up Int | Down Int | Forward Int step (x, y) (Up n) = (x, y - n) step (x, y) (Down n) = (x, y + n) step (x, y) (Forward n) = (x + n, y) step :: (Int, Int) -> Action -> (Int, Int)