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.

21 lines
538 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)
  8. . map ((\[a, b] -> (head a, read b :: Int)) . words)
  9. . lines
  10. where
  11. applymove :: (Int, Int) -> (Char, Int) -> (Int, Int)
  12. applymove (x, y) (d, v) = case d of
  13. 'f' -> (x + v, y)
  14. 'd' -> (x, y + v)
  15. 'u' -> (x, y - v)
  16. _ -> undefined -- unreachable
  17. multhem :: (Int, Int) -> Int
  18. multhem (a, b) = a * b