Skip to content

Instantly share code, notes, and snippets.

@dallarosa
Created April 16, 2012 01:43
Show Gist options
  • Save dallarosa/2395914 to your computer and use it in GitHub Desktop.
Save dallarosa/2395914 to your computer and use it in GitHub Desktop.
Integer circular shift
def rotate(x,n):
result = x
mag_x = len(str(x))
for i in range(0,n):
mag_res = len(str(result))
first = 0 if mag_x > mag_res else int(result/pow(10,mag_res))
tmp = result - first*pow(10,mag_res)
result = tmp*10 + first
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment