I'm trying to find a formula that can find X given Y for the formula Y = (X+1).X/2. But i'm seriously stumped... Is it possible without trial and error? I'm wish to avoid the function that has to iterate X values every time just to find a matching Y. If possible I'm looking for a solution that makes use of the modulus (%) operator. Anyone got a clue on this?
I don't know if the editor has every math function you need, but have you tried using the quadratic formula?
Not sure how I'd go about doing this. All i remember is that the quadratic formula can map Y given X, but X given Y here gives me a sort of logarithmic curve, so I don't see how it'll work.
Edit: Just to be clear I'm only dealing with values of X >= 1
@Kueken531: Go
I'm not sure how you got your final equation. My one attempted to get all X's on 1 side but it ended up as a sum (and not 1 term).
Not sure, how it is called in english... quadratic complement? Basically, you have something like x² + x. You can also write it as (x² + x + 1/4) - 1/4, which translates to (x + 1/2)² - 1/4, using binomical formulas. Now you can square-root the bracket and you are good to go ;)
As you can see, there is one square root and two additions. I saved you a multiplication! All you have to do is assume the X is actually higher than what you get from this calculation.
As you can see, there is one square root and two additions. I saved you a multiplication! All you have to do is assume the X is actually higher than what you get from this calculation.
But you bloat the code xD. Speaking of SC2, I would almost call this the greater evil. Not to mention, that SC2's fixed cannot handle a precision < 0.0625 anyways :D
Also, we don't even have the slightest idea, if the desired application would justify such a degree of optimization (or discussion, for that matter).
You all are amazing. Thanks for jogging my memory lol. It's all coming back now. If you're wondering where this question came from, I was just suddenly curious as to how we could calculate a hero's level if you only know how much experience he/she had, in the context of D&D games where experience requirements tend to be progressive 1k,2k,3k...,Nk. That's where the Y = (X+1).X/2 formula came from. :)
I'm trying to find a formula that can find X given Y for the formula Y = (X+1).X/2. But i'm seriously stumped... Is it possible without trial and error? I'm wish to avoid the function that has to iterate X values every time just to find a matching Y. If possible I'm looking for a solution that makes use of the modulus (%) operator. Anyone got a clue on this?
@Trieva: Go
I don't know if the editor has every math function you need, but have you tried using the quadratic formula?
Not sure how I'd go about doing this. All i remember is that the quadratic formula can map Y given X, but X given Y here gives me a sort of logarithmic curve, so I don't see how it'll work.
Edit: Just to be clear I'm only dealing with values of X >= 1
@Trieva: Go
Also X = (2y/x) - 1
lol.. don't we need all x terms on 1 side of the formula? :P
Uhm... we are talking about Y = (X + 1) * (X / 2), correct? So X = SquareRoot( 2Y + 1/4) - 1/2 should do the trick, right?
@Kueken531: Go
I'm getting X = Squareroot(2y + .25) - .5 myself, your y is a little different kueken.
@Trieva: Go
Edit: Aye whoops, should be X = (+ or -)(Squareroot(2y + .25)) - .5
Yeah, my bad, small error on my part. Didn't get much sleep. Also, I was never that good at mental arithmetics
Not sure, how it is called in english... quadratic complement? Basically, you have something like x² + x. You can also write it as (x² + x + 1/4) - 1/4, which translates to (x + 1/2)² - 1/4, using binomical formulas. Now you can square-root the bracket and you are good to go ;)
@FuzzYD:
the detailed way:
y=(x+1)*x/2
<=> x^2 + x = 2y
<=> x^2 + x + 1/4 = 2y + 1/4
<=> (x+1/2)^2 = 1/4(8y+1)
<=> |x+1/2| = 1/2 * sqrt(8y + 1)
<=> x + 1/2 = -1/2 * sqrt(8y + 1) v x + 1/2 = 1/2 * sqrt(8y + 1)
<=> x = 1/2 * (1 - sqrt(8y+1)) v x = -1/2 * (1 + sqrt(8y+1))
Remember people, cut down the multiplications as much as possible. Optimal calculation:
-0.35355339059327376220042218105242 +/- sqrt(y + 0.125) = 0.70710678118654752440084436210485x
As you can see, there is one square root and two additions. I saved you a multiplication! All you have to do is assume the X is actually higher than what you get from this calculation.
@Trieva: Go
Not sure I'd call this one heavy math, is from Pre-calc I. I do tend to forget how to complete the square myself if I get out of practice though....
Nice how we can all practice our algebra again regardless, lol!
@Trieva: Go
Indeed, my favorite ones to forget are synthetic division and any and all trig functions that aren't the unit circle or sin2 + cos2 = 1
But you bloat the code xD. Speaking of SC2, I would almost call this the greater evil. Not to mention, that SC2's fixed cannot handle a precision < 0.0625 anyways :D
Also, we don't even have the slightest idea, if the desired application would justify such a degree of optimization (or discussion, for that matter).
Problem solved :D
You all are amazing. Thanks for jogging my memory lol. It's all coming back now. If you're wondering where this question came from, I was just suddenly curious as to how we could calculate a hero's level if you only know how much experience he/she had, in the context of D&D games where experience requirements tend to be progressive 1k,2k,3k...,Nk. That's where the Y = (X+1).X/2 formula came from. :)