Algorithm to find the next boolean list with m 1s:
Find the rightmost 0 which has k 1s on its right
where k>0. Move a 1 into that position and move
the other (k-1) 1s all the way to the right.
nv=: 3 : 0
j=. 0 i:~ (>: +./\.) y
(j{.y),1,(1+j-#y){.1$~_1++/j}.y
)
nv^:(i.3!5) 0 0 1 1 1
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
0 1 1 1 0
1 0 0 1 1
1 0 1 0 1
1 0 1 1 0
1 1 0 0 1
1 1 0 1 0
1 1 1 0 0
I. nv^:(i.3!5) 0 0 1 1 1
2 3 4
1 3 4
1 2 4
1 2 3
0 3 4
0 2 4
0 2 3
0 1 4
0 1 3
0 1 2
(3 comb 5) -: I. nv^:(i.-3!5) 0 0 1 1 1
1
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm