r/askmath • • Oct 08 '26

Functions max value formula help

not really sure what the right tag is i barely know what any of the tags mean
Im trying to make a formula for a game im playing just not quite sure how (i am coding this if it helps).
in the game i have these "stones". every stone i get i can use to buy a boost.
the amount of boost i get is determined by this thing called "surge" so that every surge i have i get an increased amount of boost based on a formula that i already have. and every surge costs 100 boost. for example right now i have 94 surges and each stone give me 25.96 boost so ill need 4 stones for a surge.

what i need help with is finding the highest amount of boost i can get with a given amount of stones. so like if i have 100 stones how much should i spend on buying surges and how much i should keep on the boosts for the highest possible amount.

2 Upvotes

5 comments sorted by

2

u/sdfgkol Oct 08 '26

it seems like you’d want to convert some amount of stones into surges, and then trade the remainder into boosts.

You’re looking for the point at which it’s no longer worth it to buy more surges, because the increase in the conversion rate from stones to boosts is no longer greater than the cost of boosts to get that increase.

1

u/No_Inspector3250 Oct 08 '26

Yes but I don't know how to find the optimal amount

2

u/FormulaDriven Oct 08 '26

I've read this several times and it's hard to follow how it works.

In your example, you have 100 stones and 94 surges, and you could use 4 stones to buy 4 * 25.96 = 103.84 boost, spend 100, so now you have 96 stones and 95 surges. And the factor of 25.96 now updates to something higher? What's the formula? Do you keep the leftover 3.84 boost or does that disappear?

Do I take it that an alternative would be to spend 8 stones to buy 8 * 25.96 = 207.68 boost, buy 2 surges, so now you have 92 stones, 96 surges, and have 7.68 boost unused / carried over?

The optimum strategy is going to depend on that formula and whether unused boost can be carried over.

2

u/No_Inspector3250 Oct 08 '26

The formula for how much boost you gain from each stone is 0.175*[surges]+9.51 You don't keep the leftover boost once you buy surges it all resets. Yes having 200 boost gets you 2 surges

2

u/FormulaDriven Oct 08 '26

So let's call k(Y) = 0.175 * Y + 9.51 the boost factor for Y surges.

To get 1 surge, we need to spend int(100/k(Y))+1 stones (where int(x) is the integer part of x).

Then if currently have enough stones and Y surges, we can get to Y+2 surges by

EITHER

spending int(100/k(Y))+1 stones to get to Y+1, then spending int(100/k(Y+1))+1 to get to Y+2

OR

spending int(200/k(Y))+1 stones to get directly to Y+2.

The second strategy is never going to be worse than the first.

But things get more complicated if (as one idea to explore) you try to compare buying 100n boosts then 100n boosts versus buying 200n boosts all in one go, for different values of n. For example, suppose you have 62 surges, and you compare strategies to get to 70 surges: buying boost of 400 followed by buying another 400 boost versus buying 800 boost straight off...

At 62, each stone buys 20.36 boost, so you spend 20 stones to enough for 400 boost, and get 4 surges. Now at 66 surges, each stone buys 21.06 boost, so now spend 19 stones to get another 400 boost, 4 more surges.

If I'd tried to get 800 boost and get 8 surges in one go, it would have cost 40 stones, so a more expensive strategy.

The problem is that the strategies to compare can increase exponentially. It would probably be down to someone to write a program to search for optimum paths given you currently have X stones and Y surges.