Thanks to both Brian and Rob for their solutions. They both helped me improve
my understanding of working with amend.
I was surprised to find however that the looped solution is faster as well as
leaner than the more J'ish solutions.
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
rndidx=: 3 : 0
nidx=.<.0.75* */$y
~.(nidx,2)?.@:$ $y
)
rndcnts=: # ?. */@:$
amendloop=: 4 : 0
n=.''
'cnts idx'=. x
for_cnt. cnts do.
n=.n,< (>cnt) (<"1 cnt_index{::idx) } cnt_index{::y
end.
)
box_amend =: 4 : '(>{:x) (}:x) } y'
box_amendb =: 4 : '<(>1{x) (>0{x) } >y'
LOOP=: '(contents;<idx) amendloop m'
BS=: ',(,.<"1 contents,.<"1 each idx)'
BS=: BS,'((>@[EMAIL PROTECTED])`(>@{:@[)`(>@])})each "1 ,.m'
RH1=: '((<"1 each idx) ,each <"0 contents) box_amend each m'
RH2=: '((<"1 each idx),.contents) box_amendb"1 0 m'
m=: (1000 100$0);5000 40$0
idx=: rndidx each m
contents=: rndcnts each idx
ts LOOP
0.0415161703513 10857920
ts BS
0.0964354408172 15760576
ts RH1
0.0795365751792 16462144
ts RH2
0.0673653355385 14716352
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm