Skip to content

Instantly share code, notes, and snippets.

@maowug
Created April 14, 2015 09:53
Show Gist options
  • Save maowug/9417fb5fe13e371448dc to your computer and use it in GitHub Desktop.
Save maowug/9417fb5fe13e371448dc to your computer and use it in GitHub Desktop.
sqrt under 1000
function isInt(n) {
return n % 1 === 0;
}
var i, j;
var count = 0;
var uniq_d = {}
for (i = 1000; i >= 3; i--) {
uniq_d = {}
for (j = i - 1; j >= i / 1.42; j--) {
k = Math.sqrt(i * i - j * j);
if (k != 0 && isInt(k)) {
if (k in uniq_d) {
continue;
} else {
console.log(i, j, k);
count += 1;
uniq_d[j] = true;
uniq_d[k] = true;
}
}
}
}
console.log(count);//881
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment