improved js solution for project euler problem 87
This commit is contained in:
parent
230faba608
commit
38d6fc1092
1 changed files with 11 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/js24
|
#!/usr/bin/js
|
||||||
|
|
||||||
function isPrime(num) {
|
function isPrime(num) {
|
||||||
if (num === 3) {
|
if (num === 3) {
|
||||||
|
@ -31,10 +31,18 @@ print("found "+primes.length+" prime numbers");
|
||||||
let sumSet = new Set();
|
let sumSet = new Set();
|
||||||
for(let index4=0; index4 < primes.length; index4++) {
|
for(let index4=0; index4 < primes.length; index4++) {
|
||||||
let fourth = primes[index4] * primes[index4] * primes[index4] * primes[index4];
|
let fourth = primes[index4] * primes[index4] * primes[index4] * primes[index4];
|
||||||
|
if (fourth > MAX) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for(let index3=0; index3 < primes.length; index3++) {
|
for(let index3=0; index3 < primes.length; index3++) {
|
||||||
let cube = primes[index3] * primes[index3] * primes[index3];
|
let cube = fourth + primes[index3] * primes[index3] * primes[index3];
|
||||||
|
if (cube > MAX) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for(let index2=0; index2 < primes.length; index2++) {
|
for(let index2=0; index2 < primes.length; index2++) {
|
||||||
let sum = fourth + cube + primes[index2] * primes[index2];
|
let sum = cube + primes[index2] * primes[index2];
|
||||||
if (sum >= MAX) {
|
if (sum >= MAX) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue