Created
April 17, 2012 00:17
-
-
Save dallarosa/2402484 to your computer and use it in GitHub Desktop.
Recycled Numbers - http://code.google.com/codejam/contest/1460488/dashboard#s=p2
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 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
d5ca58 just broke 2 minutes limit! (1:56)