]> gitweb.factorcode.org Git - factor.git/commitdiff
math.combinatorics: fix combinations with replacement
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 1 Aug 2022 00:18:09 +0000 (17:18 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 1 Aug 2022 00:20:05 +0000 (17:20 -0700)
basis/math/combinatorics/combinatorics.factor

index ed3af83d7cf5ad3467c7f3436cb5a089139c965a..b1017ef84851320a151c05fbc98723759bf922db 100644 (file)
@@ -187,15 +187,15 @@ PRIVATE>
 :: nCk-with-replacement ( n k -- nCk )
     k 1 - n + factorial k factorial / n 1 - factorial / ; inline
 
-:: next-combination-with-replacement ( seq n -- seq )
-    seq n 1 - '[ _ = not ] find-last drop :> i
-    seq i tail-slice i seq nth 1 + '[ drop _ ] map! drop
-    seq ; inline
+:: next-combination-with-replacement ( seq n -- )
+    seq n 1 - '[ _ = not ] find-last drop [| i |
+        seq i tail-slice i seq nth 1 + '[ drop _ ] map! drop
+    ] when* ; inline
 
 :: combinations-with-replacement-quot ( seq k quot -- seq quot' )
     seq length :> n
     n k nCk-with-replacement <iota> k 0 <array> seq quot n
-    '[ drop _ [ _ nths-unsafe @ ] keep _ next-combination-with-replacement drop ] ; inline
+    '[ drop _ [ _ nths-unsafe @ ] keep _ next-combination-with-replacement ] ; inline
 
 PRIVATE>