]> gitweb.factorcode.org Git - factor.git/commitdiff
Make "divisors" work with 1 as well
authorSamuel Tardieu <sam@rfc1149.net>
Wed, 2 Sep 2009 10:06:38 +0000 (12:06 +0200)
committerSamuel Tardieu <sam@rfc1149.net>
Wed, 2 Sep 2009 10:07:23 +0000 (12:07 +0200)
basis/math/primes/factors/factors-tests.factor
basis/math/primes/factors/factors.factor

index eea59b6f9b53009326bb3211d410e2429880ca0c..02610e941e2a8544d46b891b26adfd4814915bcf 100644 (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
index da1c36196bef0b2649c45961340ce77634c331c5..c71fa18ab274b04f71987fffcfade2676247fb07 100644 (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 ;