On Thu, Apr 22, 2010 at 12:16 PM, Richard Quadling <rquadling@xxxxxxxxxxxxxx > wrote: > On 22 April 2010 14:48, Dan Joseph <dmjoseph@xxxxxxxxx> wrote: > This seems to be working ... > > <?php > function findBestFactors($Value, $GroupSize, array &$Factors = null) > { > $Factors = array(); > foreach(range(1, ceil(sqrt($Value))) as $Factor) > { > if (0 == ($Value % $Factor)) > { > if ($Factor <= $GroupSize) > { > $Factors[] = $Factor; > } > if ($Factor != ($OtherFactor = ($Value / $Factor)) > && $OtherFactor > <= $GroupSize) > { > $Factors[] = $OtherFactor; > } > } > > if ($Factor >= $GroupSize) > { > break; > } > } > > rsort($Factors); > > return reset($Factors); > } > > echo findBestFactors($argv[1], $argv[2], $Factors), PHP_EOL; > ?> > > > factors 1252398988 5000 > > outputs ... > > 4882 > > and 21 for your value 1252398 > > > Wow! thanks... I just plopped it into phped and fired off some tests, and I agree, seems to work fine. I appreciate your help today. I am still looking over the algebra stuff, and am now comparing it to your code. This will get me moving forward better in my project. Thank you! -- -Dan Joseph www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month. Promo Code "NEWTHINGS" for 10% off initial order http://www.facebook.com/canishosting http://www.facebook.com/originalpoetry