diff options
-rw-r--r-- | day11/day11.hs | 38 | ||||
-rw-r--r-- | day11/day11.input | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/day11/day11.hs b/day11/day11.hs new file mode 100644 index 0000000..cf1c4e0 --- /dev/null +++ b/day11/day11.hs @@ -0,0 +1,38 @@ +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)) diff --git a/day11/day11.input b/day11/day11.input new file mode 100644 index 0000000..6a94b4e --- /dev/null +++ b/day11/day11.input @@ -0,0 +1 @@ +872027 227 18 9760 0 4 67716 9245696 |