Skip to content

Commit f4b0c14

Browse files
committed
math.extras: adding all-removals
1 parent 2e523bf commit f4b0c14

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

extra/math/extras/extras-tests.factor

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,9 @@ tools.test ;
127127
{ 1 } [ 11 13 stein ] unit-test
128128
{ 2 } [ 14 52 stein ] unit-test
129129
{ 7 } [ 14 7 stein ] unit-test
130+
131+
{ { { 2 3 4 } { 1 3 4 } { 1 2 4 } { 1 2 3 } } } [ 1 { 1 2 3 4 } all-removals ] unit-test
132+
{ { { 3 4 } { 2 4 } { 2 3 } { 1 4 } { 1 3 } { 1 2 } } } [ 2 { 1 2 3 4 } all-removals ] unit-test
133+
{ { { 4 } { 3 } { 2 } { 1 } } } [ 3 { 1 2 3 4 } all-removals ] unit-test
134+
{ { { } } } [ 4 { 1 2 3 4 } all-removals ] unit-test
135+
{ { } } [ 5 { 1 2 3 4 } all-removals ] unit-test

extra/math/extras/extras.factor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,6 @@ M:: vose random* ( obj rnd -- elt )
410410
dup obj probs>> nth-unsafe { float } declare rnd random-unit* >=
411411
[ obj alias>> nth-unsafe { fixnum } declare ] unless
412412
obj items>> nth-unsafe ;
413+
414+
:: all-removals ( n seq -- seqs )
415+
seq length <iota> n over '[ _ swap diff seq nths ] map-combinations ;

0 commit comments

Comments
 (0)