math.combinatorics: produce type of sequence in selections.
parent
85acdb2520
commit
b646d1e1b8
|
@ -79,6 +79,8 @@ IN: math.combinatorics.tests
|
|||
{ 2 1 1 } { 2 1 2 } { 2 2 1 } { 2 2 2 } } ]
|
||||
[ { 1 2 } 3 selections ] unit-test
|
||||
|
||||
{ { "aa" "ab" "ac" "ba" "bb" "bc" "ca" "cb" "cc" } }
|
||||
[ "abc" 2 selections ] unit-test
|
||||
|
||||
{ V{ { 1 2 } { 1 3 } } }
|
||||
[ { 1 2 3 } 2 [ { 1 } head? ] filter-combinations ] unit-test
|
||||
|
|
|
@ -189,8 +189,8 @@ INSTANCE: combinations immutable-sequence
|
|||
<PRIVATE
|
||||
|
||||
: (selections) ( seq n -- selections )
|
||||
[ [ 1array ] map dup ] [ 1 - ] bi* [
|
||||
cartesian-product concat [ { } concat-as ] map
|
||||
[ dup [ 1sequence ] curry { } map-as dup ] [ 1 - ] bi* [
|
||||
cartesian-product concat [ concat ] map
|
||||
] with times ;
|
||||
|
||||
PRIVATE>
|
||||
|
|
Loading…
Reference in New Issue