Some alternatives: copy3=: ,/@(#,:)&.|: copy3a=: [:,./ (#,:)
20000 (copy2a-:copy3a) b 1 20000 (copy2a-:copy3) b 1 ts '20000 copy2a b' 0.00030425237 396992 ts '20000 copy3 b' 0.00071625735 264064 NB. slower by a factor 2 ts'20000 copy3a b' 0.00035746269 263680 R.E. BOSS -----Oorspronkelijk bericht----- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Roger Hui Verzonden: zaterdag 18 maart 2006 18:33 Aan: Programming forum Onderwerp: Re: [Jprogramming] Different(and maybe more elegant) ways of copying? Variation on the copy2 theme: overshoot and then crop. copy2a=: 4 : '(x*{:$y) {."1 ,.~^:(>.2^.1>.x) y' 2000 (copy -: copy2a) b 1 ts '2000 copy2a b' 0.000196394 28352 ----- Original Message ----- From: "Roger Hui" <[EMAIL PROTECTED]> To: "Programming forum" <[email protected]> Sent: Saturday, March 18, 2006 8:59 AM Subject: Re: [Jprogramming] Different(and maybe more elegant) ways of copying? 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
