clean up math.combinatorics and add another combinator
parent
cdc1f1e041
commit
a1bb120498
|
@ -103,23 +103,26 @@ C: <combo> combo
|
||||||
: apply-combination ( m combo -- seq )
|
: apply-combination ( m combo -- seq )
|
||||||
[ combination-indices ] keep seq>> nths ;
|
[ combination-indices ] keep seq>> nths ;
|
||||||
|
|
||||||
|
: combinations-quot ( seq k quot -- seq quot )
|
||||||
|
[ <combo> [ choose [0,b) ] keep ] dip
|
||||||
|
'[ _ apply-combination @ ] ; inline
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
: each-combination ( seq k quot -- )
|
||||||
|
combinations-quot each ; inline
|
||||||
|
|
||||||
|
: map-combinations ( seq k quot -- )
|
||||||
|
combinations-quot map ; inline
|
||||||
|
|
||||||
|
: map>assoc-combinations ( seq k quot exemplar -- )
|
||||||
|
[ combinations-quot ] dip map>assoc ; inline
|
||||||
|
|
||||||
: combination ( m seq k -- seq )
|
: combination ( m seq k -- seq )
|
||||||
<combo> apply-combination ;
|
<combo> apply-combination ;
|
||||||
|
|
||||||
: all-combinations ( seq k -- seq )
|
: all-combinations ( seq k -- seq )
|
||||||
<combo> [ choose [0,b) ] keep
|
[ ] combinations-quot map ;
|
||||||
'[ _ apply-combination ] map ;
|
|
||||||
|
|
||||||
: each-combination ( seq k quot -- )
|
|
||||||
[ <combo> [ choose [0,b) ] keep ] dip
|
|
||||||
'[ _ apply-combination @ ] each ; inline
|
|
||||||
|
|
||||||
: map-combinations ( seq k quot -- )
|
|
||||||
[ <combo> [ choose [0,b) ] keep ] dip
|
|
||||||
'[ _ apply-combination @ ] map ; inline
|
|
||||||
|
|
||||||
: reduce-combinations ( seq k identity quot -- result )
|
: reduce-combinations ( seq k identity quot -- result )
|
||||||
[ -rot ] dip each-combination ; inline
|
[ -rot ] dip each-combination ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue