My solutions to Advent of Code 2021
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

20 lines
570 B

  1. module Main where
  2. main :: IO ()
  3. main = interact solution
  4. solution :: String -> String
  5. solution = show
  6. . multhem
  7. . foldl applymove (0, 0, 0)
  8. . map ((\[a, b] -> (head a, read b :: Int)) . words)
  9. . lines
  10. where
  11. applymove :: (Int, Int, Int) -> (Char, Int) -> (Int, Int, Int)
  12. applymove (x, y, a) (d, v) = case d of
  13. 'f' -> (x + v, y + v * a, a)
  14. 'd' -> (x, y, a + v)
  15. 'u' -> (x, y, a - v)
  16. _ -> undefined -- unreachable
  17. multhem :: (Int, Int, Int) -> Int
  18. multhem (a, b, _) = a * b