Make "divisors" work with 1 as well

db4
Samuel Tardieu 2009-09-02 12:06:38 +02:00
parent e3f5452502
commit 21a89bab0e
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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 ;