G
Guest
I'm trying to come up with a good algorithm to do the following:
Given a list 'A' to be operated on, and a list 'I' of indices into 'A',
rotate the i'th elements of 'A' left or right by one position.
Here's are some examples:
A = [a, b, c, d, e, f]
I = [0, 3, 4]
rotate(A, I, 'left') --> [b, c, d, e, f, a]
rotate(A, I, 'right') --> [b, a, c, f, d, e]
I = [1, 3, 4]
rotate(A, I, 'left') --> [b, a, d, e, c, f]
rotate(A, I, 'right') --> [a, c, b, f, d, e]
Any ideas?
Given a list 'A' to be operated on, and a list 'I' of indices into 'A',
rotate the i'th elements of 'A' left or right by one position.
Here's are some examples:
A = [a, b, c, d, e, f]
I = [0, 3, 4]
rotate(A, I, 'left') --> [b, c, d, e, f, a]
rotate(A, I, 'right') --> [b, a, c, f, d, e]
I = [1, 3, 4]
rotate(A, I, 'left') --> [b, a, d, e, c, f]
rotate(A, I, 'right') --> [a, c, b, f, d, e]
Any ideas?