Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getTriplet() {
- var a, b, c;
- // Iterate through possible values for a, which will be between 1-1000
- for (a = 1; a <= 1000; a++) {
- // Iterate through possible values for b, which will be between a-1000
- for (b = a + 1; b <= 1000; b++) {
- // Set value of c so that a + b + c = 1000
- c = 1000 - a - b;
- // If a^2 + b^2 = c^2...
- if ((a * a) + (b * b) === (c * c)) {
- // Then both conditions have been met and we can stop searching & return the product of a * b * c
- return ({
- 'product': a * b * c,
- 'a': a,
- 'b': b,
- 'c': c
- });
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement