Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Point(a,b,c){
- 'use strict';
- if (! (this instanceof Point)) return new Point(x,y);
- Object.defineProperties(this, {
- a : {
- value: a || 0,
- writable: true,
- configurable: false,
- enumerable: true
- },
- b : {
- value: b || 0,
- writable: true,
- configurable: false,
- enumerable: true
- },
- c : {
- value: c || 0,
- writable: true,
- configurable: false,
- enumerable: true
- }
- });
- }
- function findPythagoreanTriples(max) {
- 'use strict';
- var results = [],
- a = 0,
- b = 0,
- c = 0,
- limit = Math.ceil(Math.sqrt(max)/2);
- for (var m = 0; m <= limit; m++) {
- for (var n = m; 2*n*(m+n) < max; n++) {
- if (m && n && m !== n) {
- a = n*n-m*m;
- b = 2*m*n;
- c = m*m+n*n;
- if (isPythagoreanTriple(a,b,c)) {
- results.push(new Point(a, b, c))
- }
- }
- }
- }
- return results;
- }
- function isPythagoreanTriple(a,b,c) {
- 'use strict';
- return c*c === a*a + b*b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement