11 part 1 done

This commit is contained in:
pingu 2024-12-11 09:28:42 +01:00
parent 5796436650
commit a20210b96f
2 changed files with 25 additions and 2 deletions

View File

@ -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 ()

1
inputs/11 Normal file
View File

@ -0,0 +1 @@
3279 998884 1832781 517 8 18864 28 0