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 java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
public class JavaPalindrome2 { | |
public static void main(String[] args) throws Exception { | |
String line = ""; | |
Long ini = System.currentTimeMillis(); |
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]: |
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 java.io.BufferedReader; | |
import java.io.FileReader; | |
public class JavaPalindrome { | |
public static void main(String[] args) throws Exception { | |
String line = ""; | |
BufferedReader reader = new BufferedReader(new FileReader("seed.txt")); | |
int totalPalindromes = 0; | |
long ini = System.currentTimeMillis(); |
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 | |
start = time.time() | |
total_count = 0 | |
with open (r'seed.txt') as file: | |
rangos = ((int(rango) for rango in line.split()) for line in file) | |
for rango_ini, rango_final in rangos: | |
nums = (str(num) for num in xrange(rango_ini, rango_final + 1)) | |
total_count += sum(1 for num in nums if num == num[::-1]) | |
end = time.time() | |
print ("Total de palimdromes: {0}".format(total_count)) |