Handbook
Glossary
<n-groups> ( seq n -- groups )
Vocabulary
grouping
.
extras
Inputs
seq
a
sequence
n
an
integer
Outputs
groups
an
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
USING:
kernel
math
sequences
;
IN:
grouping.extras
::
<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
;