import Data.List type Stone = Int atoi :: String -> Stone atoi = read maybeSplitDigs :: Stone -> Maybe (Stone, Stone) maybeSplitDigs s | even ln = Just (s `divMod` md) | otherwise = Nothing where ln = ceiling $ logBase 10 $ fromIntegral s md = 10 ^ (ln `div` 2) blink :: [Stone] -> [Stone] -> [Stone] blink acc [] = reverse acc blink acc (h:t) | h == 0 = blink (1:acc) t | h == 1 = blink (2024:acc) t | Just (left, right) <- maybeSplitDigs h = blink (right:left:acc) t | otherwise = blink (h * 2024:acc) 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 . 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 stones))