Re: Rotating arbitrary sets of elements within a list

2005-04-08 Thread wes weston
[EMAIL PROTECTED] wrote: 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

Re: Rotating arbitrary sets of elements within a list

2005-04-08 Thread phil_nospam_schmidt
[EMAIL PROTECTED] wrote: > 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. Ok, here's what I've got. It seems to work right, but can it be

Re: Rotating arbitrary sets of elements within a list

2005-04-08 Thread wes weston
[EMAIL PROTECTED] wrote: 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

Rotating arbitrary sets of elements within a list

2005-04-08 Thread phil_nospam_schmidt
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,