math.combinatorics: produce type of sequence in selections.

db4
John Benediktsson 2013-04-06 13:06:23 -07:00
parent 85acdb2520
commit b646d1e1b8
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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>