From e8c12abfbf427ad20a6077bd9b874bdec5ae74f5 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 31 Jul 2022 17:18:09 -0700 Subject: [PATCH] math.combinatorics: fix combinations with replacement --- basis/math/combinatorics/combinatorics.factor | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/basis/math/combinatorics/combinatorics.factor b/basis/math/combinatorics/combinatorics.factor index ed3af83d7c..b1017ef848 100644 --- a/basis/math/combinatorics/combinatorics.factor +++ b/basis/math/combinatorics/combinatorics.factor @@ -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 k 0 seq quot n - '[ drop _ [ _ nths-unsafe @ ] keep _ next-combination-with-replacement drop ] ; inline + '[ drop _ [ _ nths-unsafe @ ] keep _ next-combination-with-replacement ] ; inline PRIVATE> -- 2.34.1