Re: Math Question....
| From: | Dan Joseph | Date: | Thu, 22 Apr 2010 16:42:13 +0000 |
| Subject: | Re: Math Question.... | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304435@lists.php.net to get a copy of this message | ||
On Thu, Apr 22, 2010 at 12:16 PM, Richard Quadling <rquadling@googlemail.com
> wrote:
> On 22 April 2010 14:48, Dan Joseph <dmjoseph@gmail.com> 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