[Tutor] cyclically rotate a list.

kevin parks kp87@lycos.com
Thu, 14 Feb 2002 16:30:39 +0900


How does one cyclically rotate a list (of arbitary size)
so that given a list x= [0, 1, 2, 3, 4, 5, 6] one could say:
rotate(x, y=0) -->[0, 1, 2, 3, 4, 5, 6]
rotate(x, y=1) -->[1, 2, 3, 4, 5, 6, 0]

yeilding list like so (with y going modulo the list size 
i suppose):

[0, 1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6, 0]
[2, 3, 4, 5, 6, 0, 1]
[3, 4, 5, 6, 0, 1, 2]
.
.
.
[6, 0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, 4, 5, 6]


I am hurting my brain on this one.


Love is in the Air!

Check out Cupid School where you will learn from Matchmaker's
best and brightest.

At Cupid School you'll learn how to pair up hopeful romantics
with one another, based on their personal preferences.
If you do well- you'll be rewarded with your own
set of love bow and arrows!

Good Luck!

http://ecard.matchmaker.com/cupid0202/cupid0202.html