Skip to content

Instantly share code, notes, and snippets.

@zane
Created January 15, 2010 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zane/278298 to your computer and use it in GitHub Desktop.
Save zane/278298 to your computer and use it in GitHub Desktop.
import math
def rotate(array, steps):
steps = steps % len(array)
reverse(array, 0, len(array) - 1)
reverse(array, 0, steps - 1)
reverse(array, steps, len(array) - 1)
return array
def reverse(array, start, end):
for x in range(math.ceil(((float(end) - float(start)) / 2))):
temp = array[start + x]
array[start + x] = array[end - x]
array[end - x] = temp
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment