# Characteristics, what's the inverse of (x*(x+1))/2? [closed]

In my game you can spend points to upgrade characteristics. Each characteristic has a formula like:

A) out = in : for one point spent, one pont gained (you spend 1 point on Force so your force goes from 5 to 6)

B) out = last level (starting at 1) : so the first point spent earns you 1 point, the next point spent earns you an additional 2 and so on (+3,+4,+5...)

C) The inverse of B) : You need to spend 1 point to earn one, then you need to spend 2 to earn another one and so on.

I have already found the formula for calculating the actual level of B when points spent = x :

charac = (x*(x+1))/2

But I'd like to know what the "reverse" version of B) (usable for C) is, ie. if I have spent x points, how many have I earned if 1 spent gives 1, 1+2=3 gives 2, 1+2+3=6 gives 3 and so on.

I know I can just calculate the numbers but I'd like to have the formula because its neater and so that I can stick it in an excel sheet for example...

Thanks!

ps. I think I have nailed it down to something like charac = sqrt( x*m +k) but then I'm stuck doing number guessing for k and m and I feel I might be wrong anyway as I get close but never hits the spot.

-

## closed as off topic by Byte56♦, Josh Petrie♦, RicketOct 26 '12 at 16:07

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Is this what you're looking for? – William Mariager Oct 26 '12 at 13:41
Off topic and probably a little too localized as well. – Byte56 Oct 26 '12 at 14:28
I believe the answer would involve a bit of Calculus, specifically something under the topic of "Series and Sequences". Reminds me vaguely of my second-year college courses, but I can't be any more specific than that for lack of remembering the details. Math.SE could be the place to ask this, or some other math type forum. Hopefully you have some keywords to go from now. – Ricket Oct 26 '12 at 16:09
Is SO getting harder rules? I'm developing a game, I have trouble with a calculation with characteristics and that's not game-developer related? Thanks for the answers though, really on the spot (Excellent link William!) and I actually was over on math.se but it seemed like a question 'not complicated enough' for them and here on GD I got 2 fine answers :-) – Valmond Oct 26 '12 at 16:23

You should probably ask it on Math.SE ...

Short version: Your formula is generally known as "sum of integers", a special case of a power sum and generally written as follows:

Calculating the inverse requires solving the quadratic equation 0.5x2 + 0.5x - charac = 0 for x.

In the basic formula for solving such (see the link for explanation), we can set

a = 0.5

b = 0.5

c = -charac

.. and calculate that the results are ...

x = (-0.5 ± √(0.52 + 4 x 0.5 x charac)) / 2 x 0.5 = -0.5 ± √(2 x charac + 0.25)

Since one of the results is always negative it can't be true, so this leaves us with the following formula, which is positive for all positive real-valued charac:

x = √(2 x charac + 0.25) - 0.5

In most cases you'll probably want to round the result down to the nearest integer.

-
you should probably use * for multiplication denotation, because your solving of the quadratic formula is a little confusing if you aren't familiar with the quadratic formula... it looks like you've got a variable in your solution (2 x charac) – derivative Oct 26 '12 at 16:04
@derivative: Variables are in italics. – Martin Sojka Oct 26 '12 at 17:57