I toyed a bit with John Randall's 'run' verb ( http://www.jsoftware.com/jwiki/NYCJUG/2012-10-10 ) and got some speedup by starting with an rotated (3 places to the right) index vector:

   ts 'P=.{. display 1 run ~ i.9'
19.1419 3.4871e7
   ts 'Q=.{. display 1 run ~_3|. i.9'
2.83672 3.48714e7

note: reorder the first three rows of Q

   P-: (0 1 2) {`(_1&|.@[)`]} Q
1


run=: 3 : 0
y run ~i.9
:
n=. 0
r=. 0 9 $ 0
stack=. ,<,: x
while. (#stack) *. n<y do.
  top=. >{: stack
  stack=. }: stack
  if. 9=# top do.
    r=. r,A. top
    n=. >:n
  else.
    stack=. stack,|. <"_1 trim xtend top
  end.
end.
r
)

--
Met vriendelijke groet,
@@i = Arie Groeneveld

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to