Skip to content

Commit

Permalink
math.extras: adding all-removals
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Dec 8, 2024
1 parent 2e523bf commit f4b0c14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions extra/math/extras/extras-tests.factor
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ tools.test ;
{ 1 } [ 11 13 stein ] unit-test
{ 2 } [ 14 52 stein ] unit-test
{ 7 } [ 14 7 stein ] unit-test

{ { { 2 3 4 } { 1 3 4 } { 1 2 4 } { 1 2 3 } } } [ 1 { 1 2 3 4 } all-removals ] unit-test
{ { { 3 4 } { 2 4 } { 2 3 } { 1 4 } { 1 3 } { 1 2 } } } [ 2 { 1 2 3 4 } all-removals ] unit-test
{ { { 4 } { 3 } { 2 } { 1 } } } [ 3 { 1 2 3 4 } all-removals ] unit-test
{ { { } } } [ 4 { 1 2 3 4 } all-removals ] unit-test
{ { } } [ 5 { 1 2 3 4 } all-removals ] unit-test
3 changes: 3 additions & 0 deletions extra/math/extras/extras.factor
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,6 @@ M:: vose random* ( obj rnd -- elt )
dup obj probs>> nth-unsafe { float } declare rnd random-unit* >=
[ obj alias>> nth-unsafe { fixnum } declare ] unless
obj items>> nth-unsafe ;

:: all-removals ( n seq -- seqs )
seq length <iota> n over '[ _ swap diff seq nths ] map-combinations ;

0 comments on commit f4b0c14

Please sign in to comment.