Skip to content

Instantly share code, notes, and snippets.

@dallarosa
Created April 17, 2012 00:17
Show Gist options
  • Save dallarosa/2402484 to your computer and use it in GitHub Desktop.
Save dallarosa/2402484 to your computer and use it in GitHub Desktop.
import sys
import math
def solution():
l_range = xrange
l_int = int
l_str = str
for index,line in enumerate(open(sys.argv[1])):
if index != 0:
if len(line) == 3:
continue
number_list = line.split(" ")
counter = set()
counter_add = counter.add
a = l_int(number_list[0])
b = l_int(number_list[1])
mag = len(number_list[0]) - 1
power_mag = 10**mag
for m in l_range(a,b):
str_m = l_str(m)
if str_m[-1:]+str_m[:-1] == str_m:
continue
n = m
for j in l_range(0,mag):
first = l_int(n/power_mag)
tmp = n - first*power_mag
n = tmp*10 + first
if n <= b and m >= a and m < n :
value = str_m+"-"+l_str(n)
if value not in counter:
counter_add(value)
print "Case #"+l_str(index)+": "+l_str(len(counter))
solution()
@dallarosa
Copy link
Author

d5ca58 just broke 2 minutes limit! (1:56)

@dallarosa
Copy link
Author

1:40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment