Created
April 23, 2013 18:45
-
-
Save juanj032/5446260 to your computer and use it in GitHub Desktop.
Numeros palindromes
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
(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