AoC/2021/day02/day02.hs

16 lines
484 B
Haskell
Raw Normal View History

2021-12-05 21:00:32 +01:00
import Control.Arrow
main :: IO ()
main = do
2021-12-09 23:43:50 +01:00
input <-
map (head . words &&& read . flip (:) [] . last) <$> lines <$>
readFile "input"
print $ (\(x, y, _, d2) -> (x * y, x * d2)) $ day2 input (0, 0, 0, 0)
2021-12-05 21:00:32 +01:00
2021-12-09 23:43:50 +01:00
day2 :: [(String, Int)] -> (Int, Int, Int, Int) -> (Int, Int, Int, Int)
day2 ((d, l):xs) (x, y, z, d2)
| d == "forward" = day2 xs (x + l, y, z, d2 + l * z)
| d == "up" = day2 xs (x, y - l, z - l, d2)
| d == "down" = day2 xs (x, y + l, z + l, d2)
2021-12-05 21:00:32 +01:00
day2 [] x = x