I am trying to come up with some kind of fancy solution for this:
Right now I am building some function which will allow to generate Pythagorean triples. Wikipedia for this stuff
Can’t figure out why am I getting some negative numbers with the below code.
for (let n = 1; n<= 10; n++) {
const m = n++;
const a = Math.pow(m, 2) - Math.pow(n, 2);
const b = 2 * m * n;
const c = Math.pow(m, 2) + Math.pow(n, 2);
console.log('for m:', m, 'for n:', n);
console.log('a: ', a, 'b: ', b, 'c: ', c);
console.log((Math.pow(a, 2) + Math.pow(b, 2)), Math.pow(c, 2));
console.log('---------------');
}
/*
Output:
for m: 1 for n: 2
a: -3 b: 4 c: 5
25 25
---------------
for m: 3 for n: 4
a: -7 b: 24 c: 25
625 625
---------------
for m: 5 for n: 6
a: -11 b: 60 c: 61
3721 3721
---------------
for m: 7 for n: 8
a: -15 b: 112 c: 113
12769 12769
---------------
for m: 9 for n: 10
a: -19 b: 180 c: 181
32761 32761
---------------
*/