Yet another alternative is powers of the monad ,.~ . If x is a power of 2 then the method is really short and fast. If x is not a power of 2 then more code is required.
(1024 copy b)-: ,.~^:10 b 1 ts=: 6!:2 , 7!:[EMAIL PROTECTED] ts '1024 copy b' 0.000481905 17920 ts ',.~^:10 b' 8.63238e_5 13248 copy2=: 4 : '> ,.&.>/ ,.~&.>^:(I.|.#:x) <y' 2000 (copy -: copy1) b 1 2000 (copy -: copy2) b 1 ts '2000 copy b' 0.000918273 25664 ts '2000 copy1 b' 0.000234387 41984 ts '2000 copy2 b' 0.000215949 29056 ----- Original Message ----- From: "Roger Hui" <[EMAIL PROTECTED]> To: "Programming forum" <[email protected]> Sent: Saturday, March 18, 2006 8:47 AM Subject: Re: [Jprogramming] Different(and maybe more elegant) ways of copying? An alternative is to use indexing: copy1=: ([ (* $ [EMAIL PROTECTED]) {:@[EMAIL PROTECTED]) {"1 ] 1000 (copy -: copy1) b 1 ----- Original Message ----- From: "June Kim" <[EMAIL PROTECTED]> To: "Programming forum" <[email protected]> Sent: Saturday, March 18, 2006 8:32 AM Subject: [Jprogramming] Different(and maybe more elegant) ways of copying? b=. 2 2 $'abcd' copy=.13 : ',./ > x $< y ' NB. copies the box side by side 3 copy b ababab cdcdcd 4 copy b abababab cdcdcdcd Maybe, I could use under(as in 13 : ',./ (x&$)&.< y') but the final form isn't tacit, which is not a big problem; however I'm interested in knowing other possibilities. Any suggestions? ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
