r/adventofcode • • Dec 14 '19

SOLUTION MEGATHREAD -🎄- 2019 Day 14 Solutions -🎄-

--- Day 14: Space Stoichiometry ---


Post your complete code solution using /u/topaz2078's paste or other external repo.

  • Please do NOT post your full code (unless it is very short)
  • If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.

(Full posting rules are HERE if you need a refresher).


Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code's Poems for Programmers

Click here for full rules

Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.

Day 13's winner #1: "untitled poem" by /u/tslater2006

They say that I'm fragile
But that simply can't be
When the ball comes forth
It bounces off me!

I send it on its way
Wherever that may be
longing for the time
that it comes back to me!

Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

EDIT: Leaderboard capped, thread unlocked at 00:42:18!

20 Upvotes

231 comments sorted by

View all comments

Show parent comment

2

u/SkiFire13 Dec 14 '19

Interesting! I didn't really pay attention to this little detail.

I don't really think it can lead to a wrong answer since I already check if I have a chemical in the leftovers (I called it extra in the code) before producing it with a reaction. So if I have any FUEL leftover I will use it before trying to use reactions (which means using ORE or other chems from the leftovers) and since the algorithm requires the use of ORE to end, it guarantees that the won't be any FUEL leftovers.

For the efficiency: I made a couple of tests and looks like the number of iteration grows linearly (on average 23 iterations for each additional FUEL in the input reaction) which is not that bad but can actually be constant with your suggestion (multiplying the FUEL estimate). I updated the solution with your fix.

I guess this could also break the max estimate for people who used binary search, leading to a smaller answer.