Created
April 22, 2013 19:22
-
-
Save reneolivo/5437740 to your computer and use it in GitHub Desktop.
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
var tiempoInicio = new Date().getTime(); | |
function esPalindromo(cadena) { | |
cadena = cadena.toString(); | |
return cadena == cadena.split('').reverse().join(''); | |
} | |
var fs = require('fs'); | |
fs.readFile('seed.txt', function(error, archivo) { | |
var contador = 0; | |
var lineas = archivo.toString().split("\n"); | |
for (var num in lineas) { | |
var rango = lineas[num].split(' '); | |
rango[0] = parseInt(rango[0]); | |
rango[1] = parseInt(rango[1]); | |
for(var i = rango[0]; i <= rango[1]; i++) | |
if (esPalindromo(i)) | |
contador++; | |
} | |
var tiempoFin = new Date().getTime(); | |
var tiempoTotal = (tiempoFin - tiempoInicio) / 1000; | |
console.log( 'Encontradas : ' + contador ); | |
console.log( 'Inicio : ' + tiempoInicio ); | |
console.log( 'Fin : ' + tiempoFin ); | |
console.log( 'Tiempo Total : ' + tiempoTotal ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice,
Chequeate esta optimización: https://gist.github.com/xenomuta/5496513