--- id: 5900f3761000cf542c50fe88 challengeType: 5 title: 'Problem 9: Special Pythagorean triplet' --- ## Description
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 such that a + b + c = n.
## Instructions
## Tests
```yml tests: - text: specialPythagoreanTriplet(1000) should return 31875000. testString: assert.strictEqual(specialPythagoreanTriplet(1000), 31875000); - text: specialPythagoreanTriplet(24) should return 480. testString: assert.strictEqual(specialPythagoreanTriplet(24), 480); - text: specialPythagoreanTriplet(120) should return 49920, 55080 or 60000 testString: assert([49920, 55080, 60000].includes(specialPythagoreanTriplet(120))); ```
## Challenge Seed
```js function specialPythagoreanTriplet(n) { let sumOfabc = n; // Good luck! return true; } specialPythagoreanTriplet(1000); ```
## Solution
```js const specialPythagoreanTriplet = (n)=>{ let sumOfabc = n; let a,b,c; for(a = 1; a<=sumOfabc/3; a++){ for(b = a+1; b<=sumOfabc/2; b++){ c = Math.sqrt(a*a+b*b); if((a+b+c) == sumOfabc){ return a*b*c; } } } } ```