2
$\begingroup$

Im trying to split (say) N pink, fluffy balls into M groups as evenly as possible.

Eg: 9 Balls and 4 groups, i'd have a result set of the form: {3,2,2,2}, where each value is indicating the size of each subset.

Can anyone help me understand how to write an equation or algorithm that would solve this problem?

Thanks

  • 0
    Ah yes, its flooding back to me now. cheers2012-09-20

1 Answers 1

2

If you are given $N$ and $M,$ you put $\lfloor \frac NM \rfloor+1$ in $N \pmod M$ of the groups and $\lfloor \frac NM \rfloor$ in the rest.

  • 0
    Thanks, was thinking along the lines of this. Think I was going for something like set all to n/m, then a for loop, 1 to (n Mod m) adding one.2012-09-20