Handbook
Glossary
divisors ( n -- seq )
Vocabulary
math
.
primes
.
factors
Inputs
n
a positive integer
Outputs
seq
a
sequence
Word description
Return the ordered list of divisors of
n
, including 1 and
n
.
See also
factors
,
group-factors
,
unique-factors
Definition
USING:
arrays
kernel
math.functions
ranges
sequences
sequences.product
sorting
;
IN:
math.primes.factors
:
divisors
( n -- seq )
dup
1
=
[
1array
]
[
group-factors
dup
empty?
[
[
first2
[0..b]
[
^
]
with
map
]
map
[
product
]
product-map
sort
]
unless
]
if
;