santonegro has asked for the wisdom of the Perl Monks concerning the following question:
I want to take an array consisting of X elements and break it into 3 equal sized arrays if possible. if this is not possible, then I want a few arrays with slightly more elements. here is a sample table:
number elements in array | /3 | %3 | size of each array |
---|---|---|---|
6 | 2 | 0 | 2,2,2 |
7 | 2 | 1 | 3,2,2 |
8 | 2 | 2 | 3,3,2 |
9 | 3 | 0 | 3,3,3 |
10 | 3 | 1 | 4,3,3 |
11 | 3 | 2 | 4,4,3 |
12 | 4 | 0 | 4,4,4 |
13 | 4 | 1 | 5,4,4 |
14 | 4 | 2 | 5,5,4 |
15 | 5 | 0 | 5,5,5 |
Back to
Seekers of Perl Wisdom