Created
April 16, 2012 01:43
-
-
Save dallarosa/2395914 to your computer and use it in GitHub Desktop.
Integer circular shift
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
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