Fix code duplication
parent
35a1ca3201
commit
f683c63da1
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (c) 2007, 2008 Slava Pestov, Doug Coleman, Aaron Schaefer.
|
! Copyright (c) 2007, 2008 Slava Pestov, Doug Coleman, Aaron Schaefer.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: assocs kernel math math.order math.ranges mirrors
|
USING: assocs kernel math math.order math.ranges mirrors
|
||||||
namespaces sequences sorting ;
|
namespaces sequences sequences.lib sorting ;
|
||||||
IN: math.combinatorics
|
IN: math.combinatorics
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -27,9 +27,6 @@ IN: math.combinatorics
|
||||||
: permutation-indices ( n seq -- permutation )
|
: permutation-indices ( n seq -- permutation )
|
||||||
length [ factoradic ] dip 0 pad-left >permutation ;
|
length [ factoradic ] dip 0 pad-left >permutation ;
|
||||||
|
|
||||||
: reorder ( seq indices -- seq )
|
|
||||||
[ [ over nth , ] each drop ] { } make ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: factorial ( n -- n! )
|
: factorial ( n -- n! )
|
||||||
|
@ -42,7 +39,7 @@ PRIVATE>
|
||||||
twiddle [ nPk ] keep factorial / ;
|
twiddle [ nPk ] keep factorial / ;
|
||||||
|
|
||||||
: permutation ( n seq -- seq )
|
: permutation ( n seq -- seq )
|
||||||
tuck permutation-indices reorder ;
|
tuck permutation-indices nths ;
|
||||||
|
|
||||||
: all-permutations ( seq -- seq )
|
: all-permutations ( seq -- seq )
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue