This one's part 1 destroyed me. I had a very difficult time, trying 3 separate approaches, each one of which worked for most cases but eventually fell apart on the 5th sample or my actual puzzle input. I ended up reading a bunch of hints from the subreddit which eventually led me to a blog post describing this solution, which wasn't far off from what I had, but I was overcomplicating things. Part 2 surprised me in that I expected a simple "ore available divided by ore needed for 1 fuel" would solve it, but of course the excess chemicals produced in any given reaction meant that it wasn't that simple. So this approach uses that estimate as a lower bound, since it always underestimates, and then bisects its way to the solution (starting at the lower bound and adding 1 each time took too long). I'm sure a smarter upper bound choice could lower the runtime of this by a bit, but runtime isn't bad enough right now for me to try any additional optimizations.
7 lines
116 B
Plaintext
7 lines
116 B
Plaintext
9 ORE => 2 A
|
|
8 ORE => 3 B
|
|
7 ORE => 5 C
|
|
3 A, 4 B => 1 AB
|
|
5 B, 7 C => 1 BC
|
|
4 C, 1 A => 1 CA
|
|
2 AB, 3 BC, 4 CA => 1 FUEL |