Module aoc::year2019::day14

source ·
Expand description

§Space Stoichiometry

Sorting the reactions in topological order from FUEL at the start to ORE at the end, allows us to process each reaction only once.

Structs§

Functions§

  • ore 🔒
    Run the reactions to find ore needed. Each chemical is processed only once, so we don’t need to track excess values of intermediate chemicals.
  • To speed things up when processing, we use a temporary map to convert chemical names into contiguous indices.
  • Calculate the amount of ore needed for 1 fuel. This will be the most ore needed per unit of fuel. Larger amounts of fuel can use some of the leftover chemicals from intermediate reactions.
  • Find the maximum amount of fuel possible from 1 trillion ore with an efficient binary search.
  • Sort reactions in topological order from FUEL at the root to ORE at the leaves. Reactions may occur more than once at different depths in the graph, so we take the maximum depth.