I'm having a lot of fun learning Haskell for Advent of Code 2021! Maybe I shouldn't be trusted around computers with code this bad, but at least I'm having fun :)
Feel free to join my leaderboard at 643998-6ed04a0c.
My day 1 solution:
Feel free to join my leaderboard at 643998-6ed04a0c.
My day 1 solution:
import Data.List (tails); windows n xs = take (length xs - n + 1) $ map (take n) (tails xs) main = interact $ \input -> show $ length $ filter (\[a, b] -> b > a) $ windows 2 $ map sum $ windows 3 $ map read $ lines input
My day 2 solution:
parseCommand line = let [com, val] = words line in (com, read val :: Int) processCommand (depth, horiz, aim) (com, val) = case com of "down" -> (depth, horiz, aim + val) "up" -> (depth, horiz, aim - val) "forward" -> (depth + (aim * val), horiz + val, aim) main = interact $ \input -> let (depth, horiz, _) = foldl processCommand (0, 0, 0) $ map parseCommand $ lines input in show $ depth * horiz