...

View Full Version : Reversing a Formula



coolcamo8642
05-08-2008, 12:46 AM
I'm currently using the following function to find $a based on $L:



function XP($L) {
$a=0;
for($x=1; $x<$L; $x++) {
$a += floor($x+300*pow(2, ($x/7)));
}
return floor($a/4);
}


What I would like to do is find L based on a. For example, $a = 83 when $L = 2 and $a = 174 when $L = 3. I would like to instead input a value anywhere from 83-173 and have 2 returned.

Any suggestions would be greatly appreciated.

oesxyl
05-08-2008, 01:26 AM
I'm currently using the following function to find $a based on $L:



function XP($L) {
$a=0;
for($x=1; $x<$L; $x++) {
$a += floor($x+300*pow(2, ($x/7)));
}
return floor($a/4);
}


What I would like to do is find L based on a. For example, $a = 83 when $L = 2 and $a = 174 when $L = 3. I would like to instead input a value anywhere from 83-173 and have 2 returned.

Any suggestions would be greatly appreciated.



function XPI($a){
$x = 1;
while($a >= XP($x)){
$x++;
}
return ($x-1);
}


regards

coolcamo8642
05-08-2008, 03:00 AM
Your code is absolute perfection for what I was trying to achieve. Thank you very much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum