Last active
December 16, 2015 20:48
-
-
Save juanmboehme/5494773 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
/* | |
Mejora de este script: | |
https://gist.github.com/juanj032/5446260 | |
Basándome en este script: | |
https://gist.github.com/juanmboehme | |
Mejorado en éste: | |
https://gist.github.com/coviedo/5493821 | |
*/ | |
(function(window, document){ | |
console.time("Tiempo de computo"); | |
function isPalindrome (num) { | |
num = num.toString(); | |
return num == (num.split("").reverse().join("")); | |
} | |
var data = new XMLHttpRequest(); | |
var count = total = 0; | |
var x=y=0; | |
data.open("GET","file.txt",false); | |
data.send(); | |
data = data.responseText.split("\n"); | |
var rangos=[[],[]]; | |
while(data.length) | |
{ | |
todo = data.pop().split(" "); | |
if(rangos[0]!=' ') | |
{ | |
rangos[0].push(parseFloat(todo[0])); | |
rangos[1].push(parseFloat(todo[1])); | |
if(x==0)x=rangos[0][count]; | |
x=(rangos[0][count] < x ? rangos[0][count]:x); | |
y=(rangos[1][count] > y ? rangos[1][count]:y); | |
count++; | |
} | |
} | |
for(x=0; x < y; x++) | |
{ | |
if(x == (x.toString().split("").reverse().join(""))) | |
{ | |
for(xy = 0; xy < count; xy++) | |
{ | |
if ((rangos[0][xy] <= x) && (rangos[1][xy] >= x)) | |
{ | |
total++; | |
} | |
} | |
} | |
} | |
console.log("Total palindromes: "+total); | |
console.timeEnd("Tiempo de computo"); | |
})(window,document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment