| creating a php formula.
|
Marked

msg:4074924 | 2:11 pm on Feb 5, 2010 (gmt 0) | Hi all, I am writing a stats component which contains rankings from 1 to 100. Each stat module has a ranking. What I am trying to do is give many points for higher rankings(like 1 and 2) and few points for low rankings(such as 100). At the moment my script has something silly like this: if($rank == 1){ $points = +=10 }elseif($rank ==2){ $points = +=9 } And so on. So what I'm looking for is some kind of math formula which when you insert a number such as 1 or 2, the result is high. And if you insert a number such as 100, 99 etc. the result comes out a low number. And if there are some really smart people out there, the results get exponentially lower(for example, ranking 1 gives 10 points, ranking 100 gives 0.0001 points). But I am very unsure how to write such a formula... Can someone offer me some advice on this? Thanks in advance, Mark.
|
IanKelley

msg:4075603 | 12:59 am on Feb 7, 2010 (gmt 0) | A simple way to do it... $points[$rank] = 100000-pow($rank,3); Making... 1 = 99999 2 = 99992 ... 5 = 99875 ... 9 = 99271 ... 25 = 84375 ... 45 = 8875 The above example goes into negative points after rank 47, however if you are comparing items based on relative point difference that won't be a problem. You can play with the initial number (100000) if you need to keep numbers in the positive at higher ranks. A value of one million will cause rank 100 to be worth 0 points. Increase or decrease the number of times you multiply $rank (second attribute of the pow function) to alter how much change happens between ranks.
|
Marked

msg:4075623 | 1:58 am on Feb 7, 2010 (gmt 0) | Thank you for your reply, I quite like this idea, I'm going to try it out and see what results I get. I did come up with a much simpler way where the rank was divided by its square: ($counter / ($counter * ($counter / 2)) * 10). Thanks again.
|
|
|