-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler009.js
More file actions
28 lines (22 loc) · 794 Bytes
/
euler009.js
File metadata and controls
28 lines (22 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
// a² + b² = c²
// For example, 3² + 4² = 9 + 16 = 25 = 5².
// There exists exactly one Pythagorean triplet for which a + b + c = 1000.
// Find the product abc.
var m = 2;
var n = 1;
var a = 0;
var b = 0;
var c = 0;
for (m=2; m<25; m++) {
for (n=1; n<m; n++) {
a = (m*m) - (n*n)
b = 2*(m*n)
c = (m*m) + (n*n)
sum = a+b+c
if (sum === 1000) {
console.log ('a = ' + a + ', b = ' + b + ', c = ' + c + ', sum = ' + sum + ', product = ' + a*b*c)
}
}
}
// There are some quite interesting visualisations and implications to pythagorean triples. May consider using them for generating predictable numbers for terrain generation.