|
|
|
|
|
by basemntunivrse
1615 days ago
|
|
This is really cool, nice idea! Also, the following script might help to make the game more accessible (or to help you cheat :P) - // note: game doesn't seem to automatically clear at the end, so in the dev console use:
// window.localStorage.clear();
// then refresh the page
const prime = n => {
for (let i = 2, s = Math.sqrt(n); i <= s; i++) {
if (n % i === 0) {
return false;
}
}
return n > 1;
}
const generateNums = digits => (
m => [...Array(9 * m).keys()].map(i => i + m)
)(Math.pow(10, digits - 1));
const generate5DigitPrimes = () => generateNums(5).filter(prime);
const all5DigitPrimes = generate5DigitPrimes();
// updated to take an optional array (defaults to all5DigitPrimes)
// this means you can chain the check function to do things that normal regex can't do
// e.g. check(/some_regex/, check(/some_other_regex/))
const check = (r, a = all5DigitPrimes) => a.filter(p => r.test('' + p));
Usage:paste the above code into the dev console type 'all5DigitPrimes' and press Enter to see a list of all 5-digit primes type 'check(/some_regular_expression/)' to see a filtered list of primes that match your regular expression |
|
https://pastebin.com/sQtekXCW