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.
function pythagoreanTriplet(n) {
for (let a = 1; a < n; a++) {
for (let b = a + 1; b < n; b++) {
for (let c = b + 1; c < n; c++) {
if (a + b + c === n && a * a + b * b === c * c) {
return a * b * c;
}
}
}
}
}
Thoughts:
this is probably the first problem that I looked at and didn't know where to start myself, it's only problem 9 but I would probably need an hour or two working on it to solve it, so fair play copilot for getting it done in less than 30 seconds.