Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,10 @@
Number.prototype.isPrime = function() {
let i = 2, num = this;
if (num == 0 || num == 1) return false;
if (num == 2) return true;
while (i <= Math.ceil(Math.sqrt(num))) {
if (num % i == 0) return false;
i++;
}
return true;
}

View file

@ -0,0 +1,13 @@
function isUnprimable(num) {
if (num < 100 || num.isPrime()) return false;
let arr = num.toString().split('');
for (let x = 0; x < arr.length; x++) {
let lft = arr.slice(0, x),
rgt = arr.slice(x + 1);
for (let y = 0; y < 10; y++) {
let test = lft.join('') + y.toString() + rgt.join('');
if (parseInt(test).isPrime()) return false;
}
}
return true;
}

View file

@ -0,0 +1,29 @@
let unprimeables = [],
endings = new Array(10).fill('-'),
c = 1;
function chkEnds(n) {
let e = n % 10;
if (endings[e] == '-') endings[e] = n;
}
console.time('I');
while (unprimeables.length < 1000) {
if (isUnprimable(c)) {
unprimeables.push(c);
chkEnds(c)
}
c++;
}
console.log('The first 35 unprimeables:');
console.log(unprimeables.slice(0,35).join(', '));
console.log(`The 600th unprimeable: ${unprimeables[599].toLocaleString('en')}`);
console.log(`The 1000th unprimable: ${unprimeables[999].toLocaleString('en')}`);
console.timeEnd('I');
console.time('II');
while (endings.includes('-')) {
c++;
if (isUnprimable(c)) chkEnds(c);
}
for (c = 0; c < endings.length; c++) {
console.log(`First unprimeable ending with ${c}: ${endings[c].toLocaleString('en')}`);
}
console.timeEnd('II');