@pastafari print it out, and you'll immediately know what's up
when in doubt – print it out! :opieop:
day 14 "Elapsed time: 2.936473 msecs" "Elapsed time: 84.136665 msecs"
Hmm. Got a solution, really want to figure out how to reliably solve it. Probably a binary / other more informed search method to seek the boundary. As it is, I refined it by hand until it was close enough to solve by just injecting fuel.
Got to it late due to family time - not sure how I want to visualize this one, either. I saw some neat diagrams in Reddit.
My submission for day 14. I was afraid part 2 would be very computationally slow, but it executes in ~ 30ms :simple_smile: https://gitlab.com/dmarjenburgh/adventofcode/blob/master/src/adventofcode/year_2019.clj#L397-443
I did split stash and spendings too, but then just allowed negatives in spendings. made it noticeably more readable
but something else runs 3 times slower :opieop:
Negative spending - you just make incremental passes to sweep through and request more stock for those entries?
not sure what you mean, but if you need to "buy" 7x but recipe is 10x for 10y, your cost map would be {:y +10 :x -3}
where :x -3
is a surplus from transaction you will might use in future transactions
at first I tried to track 2 maps: cost and surplus: {:y 10}, {:x 3}
, but merging those after each transaction was a chore and slow
not terribly readable, but line 48 makes it clear(er) https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/2019/day14.clj#L43-L54
(< n amount) (assoc cost x (- n amount))
That bisect functionality is exactly what I need to steal replicate.