1

I am in the process of developing an online game. Unfortunately, I've run into an issue. I cannot figure out how to make the price of a 'level' increase at a proper rate.

I am trying to make a formula where users can purchase as many levels as they want at a time. The price of levels should increase exponentially and the total cost of a purchase should be the same no matter the amount that is purchased at a time.

For example, a player wants to purchase 1,000 levels. They could either type in 1,000 and purchase all of the levels desired at once.. OR they could keep typing in 1 and clicking the purchase button.

The total price at the end should be the same. Could anyone give me an example that would work for this?

Thanks!

1 Answers1

1

I think you're saying you want the price of the first level to be $X$ for some $X$, you want the price of the $n^{th}$ level to be $k^n\cdot X$ for some $k$, and you want to know what the cost of buying $N$ levels between $m$ and $m+N$ would be. So, you're asking what this sum is?

$$ \sum_{i = m+1}^{m+N} k^i\cdot X $$

If so, then, you can use

$$ \sum_{i=0}^{N}k^i \cdot X = X \cdot \frac{1 - k^{N+1}}{1-k} $$ to help you, as

$$ \sum_{i = m+1}^{m+N} k^i\cdot X = \sum_{i=0}^{m+N}k^i\cdot X - \sum_{i=0}^{m}k^i\cdot X \\ =X\cdot \left( \frac{k^{m+1} - k^{N+m+1} }{1-k}\right) $$

Having said that, if you're programming this for a human facing interface, you're not going to have an appreciable computation time savings using a formula like this versus just adding up all the prices for the levels they want.

  • Thank you so much! I didn't realize that I could simply iterate through each value and add it up as we go! I'll just put on a (high) cap so the server doesn't explode from too much processing... ;) – Developer990 Dec 31 '14 at 07:04
  • good idea. I think it's pretty unlikely you actually want true exponential growth, if you're going to have $1000$ levels by the way. to get any appreciable difference between $k^2$ and $k^3$, $k$ has to be large enough that $k^{1000}$ is incomprehensibly large. – Callus - Reinstate Monica Dec 31 '14 at 07:09