From 9ecb1b2b44693074a850cd96f7d5833b9cc1e944 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Wed, 11 Dec 2024 12:33:14 +0000 Subject: [Day 11] neat --- day11/day11.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/day11/day11.hs b/day11/day11.hs index cf1c4e0..158e951 100644 --- a/day11/day11.hs +++ b/day11/day11.hs @@ -28,11 +28,17 @@ blink acc (h:t) consume :: String -> [Stone] consume = map atoi . words +applyN :: Int -> (a -> a) -> a -> a +applyN n f = foldr (.) id (replicate n f) + part1 :: [Stone] -> Int -part1 = length . last . take 26 . iterate (blink []) +part1 = length . applyN 25 (blink []) + +part2 :: [Stone] -> Int +part2 = length . applyN 75 (blink []) main = do file <- readFile "day11.input" let stones = consume file putStrLn ("Part 1: " ++ (show $ part1 stones)) - --putStrLn ("Part 2: " ++ (show $ part2 mp)) + --putStrLn ("Part 2: " ++ (show $ part2 stones)) -- cgit v1.2.1