Merge branch 'for-slava' of git://git.rfc1149.net/factor

db4
Slava Pestov 2009-09-08 13:09:27 -05:00
commit c707ba5d61
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 ;