This version from Roger is almost identical to what I set up.
On Tue, 28 Aug 2007, Roger Hui wrote:
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
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm