Re: Math Question....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?php
function findBestFactors($Value, $GroupSize = INF)
	{
	foreach(range(min($GroupSize, ceil(sqrt($Value))), 1) as $Factor)
		{
		if (0 == ($Value % $Factor))
			{
			return array($Factor, $Value / $Factor);
			}
		}
	}

list($Groups, $Size) = findBestFactors($argv[1], isset($argv[2]) ?
$argv[2] : INF);
echo "$Groups groups of $Size";
?>

Supply a value and an optional maximum group size.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux