Skip to content

Instantly share code, notes, and snippets.

@ameerkat
Created April 17, 2012 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ameerkat/2402601 to your computer and use it in GitHub Desktop.
Save ameerkat/2402601 to your computer and use it in GitHub Desktop.
2012 Code Jam Qualifier C
def rotate(n, i):
j = 0
s = str(n)
while(j < i):
s = s[-1] + s[:-1]
j += 1
return int(s)
def rn(n, m):
count = 0
for i in range(n,m+1):
r_l = []
r = len(str(i))-1
for j in range(1,r+1):
r2 = rotate(i, j)
if r2 not in r_l:
r_l.append(r2)
if(i < r2 and r2 <= m and len(str(i).replace('0','')) == len(str(r2).replace('0',''))):
count += 1
return count
f = open("C-large.in")
T = f.readline()
c = 1
for line in f:
n,m = map(int, line.strip().split())
print "Case #" + str(c) + ": " + str(rn(n,m))
c += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment