Jump to content

Recommended Posts


//level 2 - 500

//level 3 - 1500

//level 4 - 3500

//level 5 - 6000




function experience($L) {

  $a=0;

  $end=0;

  for($x=1; $x<$L; $x++) {

    $a += floor($x*500)/$x;

  }

  return floor($a);

}



function Get_The_Level($exp) {

  $a=0;

  $end =0;

  for($x=1; ($end==0 && $x<10000); $x++) {

    $a += floor($x*500)/$x;

    if ($exp >= floor($a)){

} else {

  return $x;

  $end=1;

}

  }

}



function Get_Max_Exp($L){

$end=0;

if ($exp == 0){

return 457;

$end =1;

  }

for($L=1;($L<10000 && $end==0);$L++) {

  $exp = experience($L);

  //echo $exp;

  if ($exp >= $user_class->exp){

	return $exp;

	$end=1;

  }

}

}

 

I'm currently using this snippet on my site... the problem? I DON'T GET ANY OF IT!

i have it working properly, but can anyone simplify it for me please? :shrug:

Link to comment
https://forums.phpfreaks.com/topic/184487-ugh-math/
Share on other sites

The first two seem to be extremely convoluted ways of doing this:

[math]experience(L) = 500L[/math]

[math]L(experience) = \left\lfloor \frac{experience}{500} \right\rfloor + 1[/math]

 

Or in PHP...

 

function experience($L)
{
return 500 * $L;
}


function Get_The_Level($exp)
{
return floor($exp / 500) + 1;
}

 

The last one is broken, so it effectively always returns the integer 457 and makes an E_NOTICE about $exp not being set. Assuming it worked, I would expect it could also be written in a normal mathematical fashion.

Link to comment
https://forums.phpfreaks.com/topic/184487-ugh-math/#findComment-973987
Share on other sites

After playing around alot I came to this conclusion :P

 

<?php
//level 2 - 500    

//level 3 - 1500   

//level 4 - 3500   

//level 5 - 6000 

function getExp($level) {
    if ($level==2) return 500;
    $product = 0;
    for ($i=3;$i<=$level;$i++) {
         $product += $i * 500;      
    }
    return $product;
}

function getExpLevel($exp)
{
    if ($exp<1500) return 2;
    $product = 0;
    $next = 0;
    for ($i=3;$i<=10;$i++) {
         $next += $i * 500;
         if ($exp > $product && $exp < $next) { return $i;}
         $product = $next;
    }

}
echo getExp(5);
echo "<br />";
echo getExpLevel(5000);

?>

Link to comment
https://forums.phpfreaks.com/topic/184487-ugh-math/#findComment-975882
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.