Re: Math Question....

From: Date: Fri, 23 Apr 2010 15:03:47 +0000
Subject: Re: Math Question....
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-304478@lists.php.net to get a copy of this message
<?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.

« previous php.general (#304478) next »