Viktor's approach astounds me. I could not even fathom it until I explored it with trace. Below I show how I finally understood how it works. Even after using trace, I had never thought of using rotate (|.) with an a non-scalar left argument, so I had to do even more experiments to see it work Viktor's way.
ins0=:(&|.)((|:@(0&,)^:2)&.) 1 2 ins0 i. 5 5 0 1 0 2 3 4 0 0 0 0 0 0 5 6 0 7 8 9 10 11 0 12 13 14 15 16 0 17 18 19 20 21 0 22 23 24 load'trace' trace '1 2 ins0 i. 5 5' NB. value error [snip] |value error: ins0 | t_z=.(1 2) (ins0)(i.5 5) trace '1 2 ins0_base_ i. 5 5' NB. trick (Raul?) --------------- 3 Adverb ----- 1 2 (&|.)(|:@(0&,)^:2&.) |:@(0&,)^:2&.(1 2&|.) --------------- 1 Monad ------ i. 5 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 --------------- 0 Monad ------ |:@(0&,)^:2&.(1 2&|.) i.5 5 0 1 0 2 3 4 0 0 0 0 0 0 5 6 0 7 8 9 10 11 0 12 13 14 15 16 0 17 18 19 20 21 0 22 23 24 ============================== 0 1 0 2 3 4 0 0 0 0 0 0 5 6 0 7 8 9 10 11 0 12 13 14 15 16 0 17 18 19 20 21 0 22 23 24 1 2 &|. i. 3 3 NB. exploration of (&|.) 5 3 4 8 6 7 2 0 1 2 1 &|. i. 3 3 7 8 6 1 2 0 4 5 3 i. 3 3 0 1 2 3 4 5 6 7 8 On Fri, Jan 9, 2009 at 8:40 PM, Viktor Cerovski <[email protected]> wrote: > > > It can be done as follows: > > ins0=:(&|.)((|:@(0&,)^:2)&.) > > 4 4 ins0 >:i.5 5 > 1 2 3 4 0 5 > 6 7 8 9 0 10 > 11 12 13 14 0 15 > 16 17 18 19 0 20 > 0 0 0 0 0 0 > 21 22 23 24 0 25 > > 2 1 ins0 >:i.5 5 > 1 0 2 3 4 5 > 6 0 7 8 9 10 > 0 0 0 0 0 0 > 11 0 12 13 14 15 > 16 0 17 18 19 20 > 21 0 22 23 24 25 > > ins0=:(&|.)((|:@(0&,)^:2)&.) > -- (B=) ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
