function quadraticPrimes(range) {
let maxCons = 0;
let maxParams = [0,0];
for (let b = 0; b <= range; b++) {
if (!isPrime(b)) { continue; }
for (let a = -1 * range; a <= range; a++) {
let t = maxConsecutivePrimes(a, b);
if (t > maxCons) {
maxCons = t;
maxParams = [a, b];
}
}
}
console.log('The maximum of', maxCons, 'consecutive primes is achieved with parameters' + ': ' + maxParams[0] + ' -- ' + maxParams[1])
return maxParams[0] * maxParams[1];
}
console.log(quadraticPrimes(1000));
function quadFunc(a, b) {
return n => n ** 2 + a * n + b;
}
function maxConsecutivePrimes(a,b) {
let goOn = true;
counter = 0;
while (goOn) {
if (isPrime(quadFunc(a,b)(counter))) {
counter += 1} else {
goOn = false;
}
}
return counter
}
function isPrime(number) {
if (number < 0) { return false }
if (number == 1 || number == 0) {return false}
const threshold = Math.ceil(Math.sqrt(number))
for (let i = 2; i < threshold+ 1; i++) {
if ( number % i === 0) {
return false;
}
}
return true;
}