Skip to content

Instantly share code, notes, and snippets.

@juanj032
Created April 23, 2013 18:45
Show Gist options
  • Save juanj032/5446260 to your computer and use it in GitHub Desktop.
Save juanj032/5446260 to your computer and use it in GitHub Desktop.
Numeros palindromes
(function(window, document){
function isPalindrome (num) {
num = num.toString();
return num == (num.split("").reverse().join(""));
}
var inicio = Date.now();
var data = new XMLHttpRequest();
var count = 0;
data.open("GET","seed.txt",false);
data.send();
data = data.responseText.split("\n");
while(data.length){
var rangos = data.pop().split(" ");
rangos[0] = rangos[0] >> 0;
rangos[1] = rangos[1] >> 0;
for (var i = rangos[0]; i < rangos[1]; i++) {
if(isPalindrome(i))
count++;
};
}
var fin = Date.now();
var total = (fin-inicio)/1000;
console.log("Total palindromes: "+count);
console.log("Tiempo total: "+total);
})(window,document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment