Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. function getTriplet() {
  2. var a, b, c;
  3. // Iterate through possible values for a, which will be between 1-1000
  4. for (a = 1; a <= 1000; a++) {
  5. // Iterate through possible values for b, which will be between a-1000
  6. for (b = a + 1; b <= 1000; b++) {
  7. // Set value of c so that a + b + c = 1000
  8. c = 1000 - a - b;
  9. // If a^2 + b^2 = c^2...
  10. if ((a * a) + (b * b) === (c * c)) {
  11. // Then both conditions have been met and we can stop searching & return the product of a * b * c
  12. return ({
  13. 'product': a * b * c,
  14. 'a': a,
  15. 'b': b,
  16. 'c': c
  17. });
  18. }
  19. }
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement