alternate day11 with no strings

This commit is contained in:
2024-12-11 20:06:25 -08:00
parent 45c4a2997c
commit d326a4d99f
6 changed files with 94 additions and 29 deletions

View File

@@ -14,26 +14,14 @@ pfunc divide uses (_,_) : String → String × String := `(s) => {
return _$2C_(undefined, undefined, s.slice(0,l), s.slice(l))
}`
step : List Int List Int
step = go Nil
where
go : List Int List Int List Int
go acc Nil = acc
go acc (0 :: xs) = go (1 :: acc) xs
go acc (x :: xs) =
let str = show x in
if slen str % 2 == 0
then let (a,b) = divide str in go (stringToInt a :: stringToInt b :: acc) xs
else go (2024 * x :: acc) xs
foldMap : a b. {{Ord a}} {{Eq a}} (b b b) SortedMap a b List (a × b) SortedMap a b
foldMap f m Nil = m
foldMap f m ((a,b) :: xs) = case lookupMap a m of
Nothing => foldMap f (updateMap a b m) xs
Just (_, b') => foldMap f (updateMap a (f b' b) m) xs
step2 : List (Int × Int) List (Int × Int)
step2 = go Nil
step : List (Int × Int) List (Int × Int)
step = go Nil
where
go : List (Int × Int) List (Int × Int) List (Int × Int)
go acc Nil = acc
@@ -49,7 +37,7 @@ iter count parts = let x = go count parts in foldl _+_ 0 $ map snd $ toList x
where
go : Int SortedMap Int Int SortedMap Int Int
go 0 stuff = stuff
go x stuff = go (x - 1) $ foldMap _+_ EmptyMap $ step2 $ toList stuff
go x stuff = go (x - 1) $ foldMap _+_ EmptyMap $ step $ toList stuff
run : String -> IO Unit
run fn = do
@@ -59,7 +47,7 @@ run fn = do
let p1 = iter 25 stuff
putStrLn $ "part1 " ++ show p1
let p2 = iter 75 stuff
putStrLn $ "iter " ++ show p2
putStrLn $ "part2 " ++ show p2
main : IO Unit
main = do