Jump to content
php.lv forumi

Matemātika


Wuu

Recommended Posts

function exptolvl($exp){

if ($exp > 10) {

return ($exp/100)*10;

} else {

return 0;

}

}

 

Esmu visu aizmirsis, ak dievs... Nepieciešama formula kas atgriež līmeņus.

 

1lv = 10

2lv = 20

3lv = 40

4lv = 80

5lv = 160

utt..

Es zinu ka tas ir stulbi, bet nevaru jau 30 minūtes iebraukti.

Link to comment
Share on other sites

function exp2lvl($e){
 if ($e<10) return 0;
 return floor(log($e/10,2))+1;
}
for ($i=1;$i<=100;$i++){
 echo $i.' '.exp2lvl($i).'<br />';
}

 

 

2easystyle:

function e2l($e){return $e<10?0:floor(log(($e/10),2))+1;}

Edited by codez
Link to comment
Share on other sites

codez, varbūt būsi tik laipns un samazināsi arī šis rindas :D

 

	function exptoprocents($e){
		if ($e>=640) { return percent($e-640,640); }
	elseif ($e>=320) { return percent($e-320,320); }
		elseif ($e>=160) { return percent($e-160,160); }
		elseif ($e>=80) { return percent($e-80,80); }
		elseif ($e>=40) { return percent($e-40,40); }
		elseif ($e>=20) { return percent($e-20,20); }
	elseif ($e>=10) { return percent($e-10,10); }
		else { return $e; }
}

function percent($num_amount, $num_total) {
	$count1 = $num_amount / $num_total;
	$count2 = $count1 * 100;
	$count = number_format($count2, 0);
	return $count;
}

 

Atgriež procentos, cik līdz nākamajam līmenim palicis.

Link to comment
Share on other sites

function e2l($e){return $e<10?0:floor(log(($e/10),2))+1;}
function l2e($l){return $l<1?0:pow(2,$l-1)*10;}
function nl($e){return ($e-($e1=l2e($l=e2l($e))))/(l2e($l+1)-$e1)*100;}
for ($i=1;$i<=100;$i++){
 echo $i.' '.e2l($i).' '.nl($i).'%<br />';
}

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...