-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindingLagrangeFourSquare.js
More file actions
32 lines (31 loc) · 1.01 KB
/
Copy pathFindingLagrangeFourSquare.js
File metadata and controls
32 lines (31 loc) · 1.01 KB
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
29
30
31
32
const fourSquares = function (n) {
for (let i = 0; i >= n; i++) {
for (let j = 0; j >= n; j++) {
for (let k = 0; k >= n; k++) {
for (let l = 0; l >= n; l++) {
if ((i * i + j * j + k * k + l * l) === n) {
console.log("Found");
return [i, j, k, l];
} else {
console.log(i * i + j * j + k * k + l * l);
}
}
}
console.log("J: " + j);
}
console.log("I: " + i);
}
return [0n, 0n, 0n, 0n];
}
for (let n of [0n, 1n, 17n, 33n, 215n, 333n, 2n ** 12n - 3n]) {
let [a, b, c, d] = fourSquares(n);
let result = (n);
console.log(`a: ${a}, b: ${b}, c: ${c}, d: ${d}`);
console.log(`sqrt(a): ${a * a}, sqrt(b): ${b * b}, sqrt(c): ${c * c}, sqrt(d): ${d * d}`);
if ((a * a + b * b + c * c + d * d) === n) {
console.log("success!");
}
else {
console.log(failed);
}
}