Make "divisors" work with 1 as well
parent
e3f5452502
commit
21a89bab0e
|
@ -10,3 +10,4 @@ USING: math.primes.factors sequences tools.test ;
|
|||
{ { 13 4253 15823 32472893749823741 } } [ 28408516453955558205925627 factors ] unit-test
|
||||
{ { 1 2 3 4 6 8 12 24 } } [ 24 divisors ] unit-test
|
||||
{ 24 } [ 360 divisors length ] unit-test
|
||||
{ { 1 } } [ 1 divisors ] unit-test
|
||||
|
|
|
@ -43,5 +43,9 @@ PRIVATE>
|
|||
} cond ; foldable
|
||||
|
||||
: divisors ( n -- seq )
|
||||
group-factors [ first2 [0,b] [ ^ ] with map ] map
|
||||
[ product ] product-map natural-sort ;
|
||||
dup 1 = [
|
||||
1array
|
||||
] [
|
||||
group-factors [ first2 [0,b] [ ^ ] with map ] map
|
||||
[ product ] product-map natural-sort
|
||||
] if ;
|
||||
|
|
Loading…
Reference in New Issue