How do you reverse $\frac{100n(n+1)}{2}=c$ to find n given c?

67 Views Asked by At

I'm developing a game where the character experience needed by level is given by Gauss' formula multiplied by 100: $ \dfrac{100\mathrm{level}(\mathrm {level}+1)}{2}$. So the experience table is something like this:

level : experience needed

0       0
1       100
2       300
3       600

Right now I'm trying to find a way to reverse the formula, and, having the player's experience, find their level. The problem is that I can't seem to find a formula that is not a quadratic equation. Is this even possible?

3

There are 3 best solutions below

2
On BEST ANSWER

$$\dfrac{x(x+1)}{2}=y\implies (x)(x+1)=2y\implies x^2+x-2y=0\implies\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\ x=\dfrac{-1+\sqrt{1+8y}}{2}$$ Where y is $EXP/100$.

Note:This always returns positive and rational $\forall x$ generated using that equation.

0
On

A simple quadratic equation:

$$x^2+x-2y=0$$

The solution (I assume you want the positive one only):

$$x = {\sqrt{1+8y}-1\over2}$$

0
On

It is a quadratic equation, but it's quite clear that when some $x>0$ is a solution $-(x+1)<0$ is also a solution, so it should be quite simple to only find the positive solution.