Copyright | (c) Eric Mertens 2022 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2022/day/19
This solution uses a few optimizations to achieve lightning fast performance:
- Prune out any state that has the same number of bots at a given time with fewer resources
- Prune out any state that in the best case produces fewer geodes than the any state doing nothing
- Generate a new state for each purchase, not individual timesteps.
- Any bot bought is bought at the earliest possible time.
>>>
:{
:main + "Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian.\n\ \Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian.\n" :} 33 3472
Synopsis
- type Blueprint = (Int, Int, Int, Int, Int, Int, Int)
- main :: IO ()
- solve :: Int -> Blueprint -> Int
- overapprox :: Int -> State -> Int
- underapprox :: Int -> State -> Int
- keepBest :: [Res] -> [Res]
- cover :: Res -> Res -> Bool
- data State = State {}
- data Res = Res {}
- def :: State
- divUp :: Int -> Int -> Int
- step :: Blueprint -> Int -> Res -> Res -> [(Int, State)]
Documentation
overapprox :: Int -> State -> Int Source #
amount of geodes we'd end with if we bought a geode bot every single timestep
underapprox :: Int -> State -> Int Source #
amount of geodes we'd end with if we didn't buy any more geode bots
keepBest :: [Res] -> [Res] Source #
Remove all resource sets from the list that are dominated by another entry in the list.