38 lines
867 B
Haskell
38 lines
867 B
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
module Main where
|
|
|
|
import Data.Functor
|
|
import Data.List.Split
|
|
|
|
parse :: String -> [Int]
|
|
parse = (read <$>) . words
|
|
|
|
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))
|
|
]
|
|
|
|
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
|
|
solve2 = undefined
|
|
|
|
main :: IO ()
|
|
main = readFile "inputs/11" <&> parse >>= \i ->
|
|
print (solve1 i) >>
|
|
print (solve2 i)
|