11 part 1 done
This commit is contained in:
parent
5796436650
commit
a20210b96f
26
app/11.hs
26
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 ()
|
||||
|
Loading…
Reference in New Issue
Block a user