From 917ae3e4105111944c7c5757bc36d9d73a5648ea Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 15 May 2013 15:09:25 -0700 Subject: [PATCH] math.combinatorics: use cond in k-permutations. --- basis/math/combinatorics/combinatorics.factor | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/basis/math/combinatorics/combinatorics.factor b/basis/math/combinatorics/combinatorics.factor index 9052394ec2..0879e544e3 100644 --- a/basis/math/combinatorics/combinatorics.factor +++ b/basis/math/combinatorics/combinatorics.factor @@ -1,9 +1,9 @@ ! Copyright (c) 2007-2010 Slava Pestov, Doug Coleman, Aaron Schaefer, John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays assocs binary-search classes.tuple fry -hints kernel locals math math.order math.ranges memoize -namespaces sequences sequences.private sorting ; +USING: accessors arrays assocs binary-search classes.tuple +combinators fry hints kernel locals math math.order math.ranges +memoize namespaces sequences sequences.private sorting ; FROM: sequences => change-nth ; IN: math.combinatorics @@ -70,9 +70,11 @@ TUPLE: k-permutations length skip k seq ; :: ( seq k -- permutations ) seq length :> n n k nPk :> len - len zero? k zero? or [ { } ] [ - len n factorial over /i k seq k-permutations boa - ] if ; + { + { [ len k [ zero? ] either? ] [ { } ] } + { [ n k = ] [ seq ] } + [ len n factorial over /i k seq k-permutations boa ] + } cond ; M: k-permutations length length>> ; inline M: k-permutations nth-unsafe