- /*
- put this code snippet within script and call find Triplet function on body onload.
- */
- var sum = 1000;
- var a;
- var product = 0;
- function findTriplet() { //finding triplet product
- for (a = 1; a <= sum / 3; a++) {
- var b;
- for (b = a + 1; b <= sum / 2; b++) {
- var c = sum - a - b;
- if (c > 0 && (a * a + b * b == c * c)) {
- alert(a + ' ' + b + ' ' + c);
- product = (a b c);
- }
- }
- }
- alert(product);
- }
In this code snippet we will learn to solve Special Pythagorean Triplet (Euler Problem 9 Solution)
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
