diff --git a/app/11.hs b/app/11.hs index 7d7b540..1d7280e 100644 --- a/app/11.hs +++ b/app/11.hs @@ -2,11 +2,33 @@ module Main where import Data.Functor +import Data.List.Split -parse = undefined +parse :: String -> [Int] +parse = (read <$>) . words -solve1 = undefined +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 () diff --git a/inputs/11 b/inputs/11 new file mode 100644 index 0000000..5149757 --- /dev/null +++ b/inputs/11 @@ -0,0 +1 @@ +3279 998884 1832781 517 8 18864 28 0