It's not that there are four cycles, it's that the cycles have a
length of 4.  You can see this using C. which gives you each cycle.

  # C.,|.|:i.3 3
3

There are 3 cycles in the 3 by 3 case.

   >./#@> C.,|.|:i.3 3
4

The longest cycle in the 3 by 3 case has a length of 4.
(Specifically: there's one cycle of length 1 -- which means no change,
and two cycles of length 4.)

The ways of addressing this include:

1) Allocate fresh memory for the result, so we can ignore the cycle length, or
2) Do two swapping passes, which lets us live with cycles of length 2, or
3) Push the index calculation into the consuming code, so we can
ignore the cycle length.

After your description in this message I think option 3 is tempting.

Note also that you can use a lookup table for the indices, instead of
doing index arithmetic (but that's probably not worth doing on a
modern machine).

I hope this helps,

-- 
Raul

On Mon, Jan 28, 2013 at 4:07 PM, Brian Schott <[email protected]> wrote:
> I wish I had translated your code properly. [Actually, I think the
> correct translation of i2 is i2=. (j*n)-(1+k)].
> I am not sure I understand how you conclude there are 4 cycles, but I
> think I understand that swapping only in a certain order will get the
> correct result.
> In C I am working inside a loop that someone else has created and am
> trying not to alter his/her code if possilble. I am pretty sure that
> what I need is the transpose first, flip second result. I think I can
> do that in two steps with double indexed arrays outside of the loop
> which has a 13x13 array. But this is one of the most critical code
> steps and I was hoping to see if I could work complete inside the
> existing loop which goes from 0 to 168. Your warning about the
> importance of the sequence does not seem to apply if there are no
> swaps. But I have not thought of a way to do the flip and transpose
> with indices.
>
>
>
> On Mon, Jan 28, 2013 at 3:48 PM, Raul Miller <[email protected]> wrote:
>> There are two problems here.
>>
>> One is that you did not translate my code properly.  You should have used
>> i2=. (j*n)+n-(1+k)
>>
>> The other was that my code can't work right.  To illustrate this:
>>
>>    C.,|.|:i.3 3
>> +-+-------+-------+
>> |4|7 3 1 5|8 6 0 2|
>> +-+-------+-------+
>>
>> Since we have length 4 cycles in this example, simple swaps can't do
>> the job properly.
>>
>> To fix this, I think the easiest approach would be to use two loops,
>> one to do the transpose and the other to do the flip.
>>
>> Do you feel comfortable doing that, or should I try my hand at this again?
>>
>> Thanks,
>>
>> --
>> Raul
>>
>
> --
> (B=)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to