Skip to content
advent of code 2022

day 19

not enough minerals

approach

the complete solution is the go one. each blueprint is parsed into a cost vector per robot type, and dfs explores states of robots, resources and minutes left with an explicit stack. every minute it either waits or builds any robot it can afford, and it skips states it has already pushed (keyed by their string form). the main pruning is that it never keeps more robots of a type than the most that any recipe spends of that resource per minute; geode robots are uncapped.

part 1 runs 24 minutes for every blueprint and sums blueprint number times geodes. part 2 runs 32 minutes for the first three blueprints and multiplies the results. there is a second check meant to cap stockpiled resources, but its continue sits inside the inner loop, so it has no effect.

the python file has the same search but only runs it on the first blueprint for 24 minutes, and the rust one runs it on a single blueprint hard-coded as a string, so neither prints the real answers.

the trick

cap each robot type at the largest amount of that resource any recipe spends per minute; building more can never help.

go
    mv := make(vector, len(ress))
    for _, robot := range bp {
        for i := 0; i < len(robot); i += 1 {
            mv[i] = max(mv[i], robot[i])
        }
    }

    mv[len(mv) - 1] = 1000000