Here is a dead simple approach to selection with weights:
simple=:4 :0"0 1
assert. *./0<y
assert. x>:0
assert. x<#y
r=.i.0
i=.i.#y
for.i.x do.
n=.i{y
r=.r,i{~(+/\n%+/n)I.?0
i=.i-.r
end.
r
)
Example use:
(5#2) simple %2^i.8
0 1
3 1
1 0
0 2
1 2
The right argument is a weight vector, which indicates the number
of selectable arguments. The left argument indicates how many
items are to be selected.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm