Created
January 15, 2010 18:53
-
-
Save zane/278298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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