<n-groups> ( seq n -- groups )


Vocabulary
grouping.extras

Inputs
seqa sequence
nan integer


Outputs
groupsan object


Word description
Separates a sequence into n groups of roughly equal size, any remainder is distributed to the first groups. Groups are represented by slices.

Definition


:: <n-groups> ( seq n -- groups )
seq length dup n assert-positive /mod :> ( len step j ) 0 n
[| i |
dup len <
[ dup step + i j < [ 1 + ] when [ seq <slice> ] 1check ]
[ f ] if
] map-integers nip ;