On Thu, 22 Apr 2010 10:17:10 -0400
Dan Joseph <dmjos...@gmail.com> wrote:

> On Thu, Apr 22, 2010 at 10:12 AM, Stephen <stephe...@rogers.com>
> wrote:
> 
> > 1,252,398 DIV 30 = 41,746 groups of 30.
> >
> > 1,252,398 MOD 30 = 18 items in last group
> >
> Well, the only problem with going that route, is the one group is not
> equally sized to the others.  18 is ok for a group in this instance,
> but if it was a remainder of only 1 or 2, there would be an issue.
> Which is where I come to looking for a the right method to break it
> equally.
> 

My take on it:

$Items=1252398;
$MaxInGroup=30;
for ($x=$MaxInGroup; $x>1;$x--) {
        $remainder=$Items % $x;
        // Change 17 to the max amount allowed in the last group
        if ($remainder == 0 || $remainder >= 17) { // 
                $groups = (int) ($Items /$x)+1;
                echo $groups."\n";
                echo $remainder;
                break;
        }
}

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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

Reply via email to