aoc/app/11.hs

38 lines
867 B
Haskell
Raw Normal View History

2024-12-02 10:51:49 +00:00
{-# LANGUAGE LambdaCase #-}
module Main where
import Data.Functor
2024-12-11 08:28:42 +00:00
import Data.List.Split
2024-12-02 10:51:49 +00:00
2024-12-11 08:28:42 +00:00
parse :: String -> [Int]
parse = (read <$>) . words
2024-12-02 10:51:49 +00:00
2024-12-11 08:28:42 +00:00
rules :: [(Int -> Bool, Int -> [Int])]
rules =
[
((==0), const [1])
,(even . length . show, \a -> let b = show a; s = length b in chunksOf (s `div` 2) b <&> read)
,(const otherwise, pure . (*2024))
]
2024-12-02 10:51:49 +00:00
2024-12-11 08:28:42 +00:00
applyRule :: Int -> [Int]
applyRule i = head . filter (/= mempty) $ rules >>= \(f,g) -> if f i then pure $ g i else pure mempty
step :: [Int] -> [Int]
step = (applyRule =<<)
applyAmount :: Int -> a -> (a -> a) -> a
applyAmount 0 a _ = a
applyAmount n a f = f $ applyAmount (n-1) a f
solve1 :: [Int] -> Int
solve1 = length . flip (applyAmount 25) step
solve2 :: [Int] -> Int
2024-12-02 10:51:49 +00:00
solve2 = undefined
main :: IO ()
main = readFile "inputs/11" <&> parse >>= \i ->
print (solve1 i) >>
print (solve2 i)