View Single Post
Old 05-19-2008, 12:31 PM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

To find the number of rounds from players, it looks like you could use the log2 value. In PHP we don't have this function available (though it is in C) but we do have a more general log function which can take a variable base value and for our purposes that base should be 2.

To quote the PHP Manual page:
float log ( float $arg [, float $base ] )

If the optional base parameter is specified, log() returns logbase arg , otherwise log() returns the natural logarithm of arg.
In practice, we can use it like so:
PHP Code:
$players  64;
$brackets = ($players 2) - 1;     // 127
$rounds   = (int) log($players2); // 6 
Salathe is offline  
Reply With Quote