Welcome to WebmasterWorld Guest from 50.17.114.227

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

# creating a php formula.

#### Marked

2:11 pm on Feb 5, 2010 (gmt 0)

#### Junior Member

joined:June 30, 2009
posts:74

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?

Mark.

#### IanKelley

12:59 am on Feb 7, 2010 (gmt 0)

#### Senior Member

joined:Oct 4, 2001
posts: 1259

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

1:58 am on Feb 7, 2010 (gmt 0)

#### Junior Member

joined:June 30, 2009
posts:74

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.