summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-12-11 12:33:14 +0000
committerNat Lasseter <user@4574.co.uk>2024-12-11 12:33:14 +0000
commit9ecb1b2b44693074a850cd96f7d5833b9cc1e944 (patch)
tree16d3ea7be06e29da043500d3c9ce957f5d1f0eca
parentcaa336a05a5941d2734cd301da9a7f3f60ba1291 (diff)
[Day 11] neat
-rw-r--r--day11/day11.hs10
1 files 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))