From d15dbaebb452ff16f4cbbf336f5faabbb1f625de Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 6 Apr 2013 11:43:20 -0700 Subject: [PATCH] math.combinatorics: faster nCk (use integer division). --- basis/math/combinatorics/combinatorics.factor | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basis/math/combinatorics/combinatorics.factor b/basis/math/combinatorics/combinatorics.factor index 0341fc5264..83c02a618b 100644 --- a/basis/math/combinatorics/combinatorics.factor +++ b/basis/math/combinatorics/combinatorics.factor @@ -24,7 +24,7 @@ MEMO: factorial ( n -- n! ) 2dup possible? [ dupd - [a,b) product ] [ 2drop 0 ] if ; : nCk ( n k -- nCk ) - twiddle [ nPk ] keep factorial / ; + twiddle [ nPk ] keep factorial /i ; ! Factoradic-based permutation methodology @@ -112,6 +112,7 @@ PRIVATE> : next-permutation ( seq -- seq ) dup [ ] [ drop (next-permutation) ] if-empty ; + ! Combinadic-based combination methodology