Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    67
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Reversing a Formula

    I'm currently using the following function to find $a based on $L:

    PHP Code:
    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.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by coolcamo8642 View Post
    I'm currently using the following function to find $a based on $L:

    PHP Code:
    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.
    PHP Code:
    function XPI($a){
       
    $x 1;
       while(
    $a >= XP($x)){
          
    $x++;
       }
       return (
    $x-1);

    regards

  • Users who have thanked oesxyl for this post:

    coolcamo8642 (05-08-2008)

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    67
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Your code is absolute perfection for what I was trying to achieve. Thank you very much.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •