math.combinatorics: use cond in k-permutations.
parent
c1e91316d2
commit
917ae3e410
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (c) 2007-2010 Slava Pestov, Doug Coleman, Aaron Schaefer, John Benediktsson.
|
! Copyright (c) 2007-2010 Slava Pestov, Doug Coleman, Aaron Schaefer, John Benediktsson.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
|
||||||
USING: accessors arrays assocs binary-search classes.tuple fry
|
USING: accessors arrays assocs binary-search classes.tuple
|
||||||
hints kernel locals math math.order math.ranges memoize
|
combinators fry hints kernel locals math math.order math.ranges
|
||||||
namespaces sequences sequences.private sorting ;
|
memoize namespaces sequences sequences.private sorting ;
|
||||||
FROM: sequences => change-nth ;
|
FROM: sequences => change-nth ;
|
||||||
IN: math.combinatorics
|
IN: math.combinatorics
|
||||||
|
|
||||||
|
@ -70,9 +70,11 @@ TUPLE: k-permutations length skip k seq ;
|
||||||
:: <k-permutations> ( seq k -- permutations )
|
:: <k-permutations> ( seq k -- permutations )
|
||||||
seq length :> n
|
seq length :> n
|
||||||
n k nPk :> len
|
n k nPk :> len
|
||||||
len zero? k zero? or [ { } ] [
|
{
|
||||||
len n factorial over /i k seq k-permutations boa
|
{ [ len k [ zero? ] either? ] [ { } ] }
|
||||||
] if ;
|
{ [ n k = ] [ seq <permutations> ] }
|
||||||
|
[ len n factorial over /i k seq k-permutations boa ]
|
||||||
|
} cond ;
|
||||||
|
|
||||||
M: k-permutations length length>> ; inline
|
M: k-permutations length length>> ; inline
|
||||||
M: k-permutations nth-unsafe
|
M: k-permutations nth-unsafe
|
||||||
|
|
Loading…
Reference in New Issue