I have an array such as
A-B-C-D-E-F-G-H-I-J-K
I want to rotate it N places to the right; for example, if N=3, the array should end
I-J-K-A-B-C-D-E-F-G-H
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 A-B-F-E-D-C-G-H-I-J-K.
(In reply to
A possible way by Old Original Oskar!)
I found another solution, using only three flips that all start from position 1. Start with A-B-C-D-E-F-G-H-I-J-K. Then:
FLIP(1,L-N) produces H-G-F-E-D-C-B-A-I-J-K
FLIP(1,L) produces K-J-I-A-B-C-D-E-F-G-H
FLIP(1,N) produces I-J-K-A-B-C-D-E-F-G-H
|
Posted by Oskar
on 2004-04-19 20:56:04 |