math.combinatorics: speed up selections word.
parent
9a4441a80e
commit
3bf23d242d
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
USING: accessors arrays assocs binary-search classes.tuple
|
USING: accessors arrays assocs binary-search classes.tuple
|
||||||
combinators fry hints kernel kernel.private locals math
|
combinators fry hints kernel kernel.private locals math
|
||||||
math.order math.ranges namespaces sequences sequences.private
|
math.functions math.order math.ranges namespaces sequences
|
||||||
sorting strings vectors ;
|
sequences.private sorting strings vectors ;
|
||||||
IN: math.combinatorics
|
IN: math.combinatorics
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -251,10 +251,20 @@ PRIVATE>
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (selections) ( seq n -- selections )
|
:: next-selection ( seq n -- )
|
||||||
[ dup [ 1sequence ] curry { } map-as dup ] [ 1 - ] bi* [
|
1 seq length 1 - [
|
||||||
cartesian-product concat [ concat ] map
|
over 0 =
|
||||||
] with times ;
|
] [
|
||||||
|
[ seq [ + n /mod ] change-nth-unsafe ] keep
|
||||||
|
] do until 2drop ; inline
|
||||||
|
|
||||||
|
:: (selections) ( seq n -- selections )
|
||||||
|
seq length :> len
|
||||||
|
n 0 <array> :> idx
|
||||||
|
len n ^ [
|
||||||
|
idx seq nths-unsafe
|
||||||
|
idx len next-selection
|
||||||
|
] replicate ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue