Created
April 30, 2013 21:05
-
-
Save danielgpm/5491947 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 time | |
def main(): | |
start = time.time() | |
total_count = 0 | |
with open ('seed.txt','r') as file: | |
rangos = zip(*((int(rango) for rango in line.split()) for line in file)) | |
rangos_ini, rangos_final = sorted(rangos[0]), sorted(rangos[1]) | |
for num in xrange(rangos_ini[0], rangos_final[-1] + 1): | |
str_num = str(num) | |
if str_num == str_num[::-1]: | |
for i in range(len(rangos_ini)): | |
if (rangos_ini[i] <= num <= rangos_final[i]): | |
total_count += 1 | |
end = time.time() | |
print ("Total de palimdromes: {0}".format(total_count)) | |
print ("Duracion: {0:.3f} secs".format(end-start)) | |
if __name__ =="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment