cA/p + cB/(p+pA) < cB/p + cA/(p+pA)
Solving this, we get cA * (p+pA)/pA < cB * (p+pB)/pB Since the left side is all in A, if we pick the item minimizing that quantity, it is faster to buy it before any other item. So changing res.score to be res.cost * (cur_power + res.powerGain)/res.powerGain is going to be a bit faster
cA/p is just the time it would take to earn the money to buy A at the current production level - seems much simpler now.
I think the last term should be `cA/(p+pB)`. When I solve from there[1] I get `cB * pB < cA * pA`, which means that the most optimal item A will have the largest product `cA * pA`.
This would translate to:
res.score = res.cost*res.powerGain
...
}).sort(function(a,b){return b.score - a.score})
Does that check out? It seems too simple, and now that I'm thinking more about it I think this would be functionally equal to what I already have. Did I do my inequality[1] wrong?https://gist.github.com/thexa4/2da63028a1d8007dedbd0ba9432c8...
Copy and paste the code in your browser's javascript console. In Chrome it's under View/Developer/JavaScript Console.
For a good intro on how this works: https://www.khanacademy.org/computing/computer-programming/h...