Created
November 12, 2011 21:43
-
-
Save jakedobkin/1361162 to your computer and use it in GitHub Desktop.
euler 9
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
<html> | |
<body> | |
<script type="text/javascript"> | |
for (a=1;a<=1000;a++) | |
{ | |
for (b=a+1;b<=1000;b++) | |
{ | |
c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2)); | |
sum = a+b+c; | |
product = a*b*c; | |
if (sum==1000) | |
{ | |
document.write(product); | |
} | |
} | |
} | |
</script> | |
</body> | |
</html> |
a = 293;
sum = 0;
while (sum != 1000) {
a--;
b=(1000-2*a);
while(b>a && !(sum==1000)) {
b--;
c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
if (Math.floor(c) == c) {
// console.log(a, b, Math.floor(c), Math.sqrt(Math.pow(c,2)));
sum = a+b+c;
}
}
}
product = a*b*c;
console.log(sum, product, a, b, c);
and computing product can be outside the loop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, a couple other minor nits (I never finished writing that is_int function, which didn't work) and of course while b>a is better than b > 10.