sln_2022_19
Copyright(c) Eric Mertens 2022
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

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

Documentation

main :: IO () Source #

>>> :main
1306
37604

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.

cover :: Res -> Res -> Bool Source #

Relation for the first element dominating the second.

data State Source #

Constructors

State 

Fields

Instances

Instances details
Show State Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> State -> ShowS #

show :: State -> String #

showList :: [State] -> ShowS #

Eq State Source # 
Instance details

Defined in Main

Methods

(==) :: State -> State -> Bool #

(/=) :: State -> State -> Bool #

Ord State Source # 
Instance details

Defined in Main

Methods

compare :: State -> State -> Ordering #

(<) :: State -> State -> Bool #

(<=) :: State -> State -> Bool #

(>) :: State -> State -> Bool #

(>=) :: State -> State -> Bool #

max :: State -> State -> State #

min :: State -> State -> State #

data Res Source #

Constructors

Res 

Fields

Instances

Instances details
Show Res Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> Res -> ShowS #

show :: Res -> String #

showList :: [Res] -> ShowS #

Eq Res Source # 
Instance details

Defined in Main

Methods

(==) :: Res -> Res -> Bool #

(/=) :: Res -> Res -> Bool #

Ord Res Source # 
Instance details

Defined in Main

Methods

compare :: Res -> Res -> Ordering #

(<) :: Res -> Res -> Bool #

(<=) :: Res -> Res -> Bool #

(>) :: Res -> Res -> Bool #

(>=) :: Res -> Res -> Bool #

max :: Res -> Res -> Res #

min :: Res -> Res -> Res #

divUp :: Int -> Int -> Int Source #

step :: Blueprint -> Int -> Res -> Res -> [(Int, State)] Source #