Raul,

If I have translated your code correctly, then I don't think it
produces the correct results.

   rtf =: monad define  NB. Raul's transpose flip
n=. %:#y
r=. y
for_j. i. n do.
for_k. i. n do.
i1=. j+n*k
i2=. j*n-(1+k)
if. i1 < i2 do.
        t=.i1{r
        r=.(i2{r) i1}r
        r=.t i2}r
        end.
end.
end.
r
)
   rtf i. 9
0 2 4 3 1 5 6 7 8

By efficiency I mean that minimizing swapping stuff. But that may not
be a good efficiency, I suppose.


On Mon, Jan 28, 2013 at 2:41 PM, Raul Miller <[email protected]> wrote:
> On Mon, Jan 28, 2013 at 2:34 PM, Brian Schott <[email protected]> wrote:
>> I realize there are approaches like Raul and Devon are proposing that
>> use 2D array indexing and require two array resequencing, but I was
>> hoping to do both steps at once arithmetically to resequence the
>> single index list to achieve efficiency.
>
> What do you mean by efficiency?
>
> Time?
>
> Space?
>
> Code?
>
> Forum? (But I'll stop trying to move this to chat, I guess...)
>
> Anyways, here's an in-place implementation:
>
> int * whatever(int n, int * r) {
>         for (int j= 0; j < n; j++)
>                 for (int k= 0; k < n; k++) {
>                         int i1= j+n*k;
>                         int i2= j*n-(1+k);
>                         if (i1 < i2) {
>                                 int t= r[i1];
>                                 r[i1]= r[i2];
>                                 r[i2]= t;
>                         }
>                 }
>         return r;
> }
>
> --
> Raul

-- 
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to