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 part1 :: [Stone] -> Int part1 = length . last . take 26 . iterate (blink []) main = do file <- readFile "day11.input" let stones = consume file putStrLn ("Part 1: " ++ (show $ part1 stones)) --putStrLn ("Part 2: " ++ (show $ part2 mp))