All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Rotating an array (Posted on 2004-04-19)
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.

 See The Solution Submitted by e.g. Rating: 4.0000 (13 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 re(2): 10 step method | Comment 21 of 26 |
(In reply to re: 10 step method by Federico Kereki)

Thanks for pointing that out (same to Charlie).  I guess the answer would then be:
FLIP(1,11)=K-J-I-H-G-F-E-D-C-B-A
FLIP(1,3)=I-J-K-H-G-F-E-D-C-B-A
FLIP(4,11)=I-J-K-A-B-C-D-E-F-G-H

Correct?

 Posted by logischer Verstand on 2004-04-23 22:13:06

 Search: Search body:
Forums (0)