The algorithm is to rotate each “ring”, working from the external to the most internal.
AAAAA ABBBA ABCBA ABBBA AAAAA
The algorithm will rotate all A first, then B, and then C. To rotate the ring, you must immediately move 4 values.
Index i ranges from 0..ring-width-1, for example. for A, the width is 5.
(i,0) -> temp (0, Ni-1) -> (i, 0) (Ni-1, N-1) -> (0, Ni-1) (N-1, i) -> (Ni-1, N-1) temp -> (N-1, i)
Then this is repeated for each subsequent inner ring, compensating for the coordinates, reducing the width of the ring by 2.
[Another answer came up with code, so I won’t repeat it.]
mdma Aug 15 '10 at 18:50 2010-08-15 18:50
source share