I have an array such as
ABCDEFGHIJK
I want to rotate it N places to the right; for example, if N=3, the array should end
IJKABCDEFGH
Assume that the only available operation is a FLIP method that can invert any portion of the array. For example, applied to the original array FLIP(3,6) would produce ABFEDCGHIJK.
Surely the answer is more simple than any we have seen,
The first move should be to flip the entire array: FLIP(1,M)
the second would be to then FLIP(1,N)
the final move would be to FLIP(N+1,M).
ABCDEFGHIJK
KJIHGFEDCBA
IJKHGFEDCBA
IJK
ABCDEFGH
the above works because you are inverting all the letters in between your to numbers, see e.g. in the question.
"Assume that the only available operation is a FLIP method that can
invert any portion of the array. For example, applied to the original
array FLIP(3,6) would produce AB
FEDCGHIJK".

Posted by Juggler
on 20040419 18:40:49 