2020-03-12 16:46:40 +01:00
|
|
|
// This is a script to calculate prime numbers.
|
|
|
|
|
2020-03-14 07:30:44 +01:00
|
|
|
const MAX_NUMBER_TO_CHECK = 10000; // 1229 primes
|
2020-03-12 16:46:40 +01:00
|
|
|
|
|
|
|
let prime_mask = [];
|
|
|
|
prime_mask.pad(MAX_NUMBER_TO_CHECK, true);
|
|
|
|
|
2020-03-14 07:57:59 +01:00
|
|
|
prime_mask[0] = prime_mask[1] = false;
|
2020-03-12 16:46:40 +01:00
|
|
|
|
|
|
|
let total_primes_found = 0;
|
|
|
|
|
|
|
|
for p in range(2, MAX_NUMBER_TO_CHECK) {
|
|
|
|
if prime_mask[p] {
|
|
|
|
print(p);
|
|
|
|
|
|
|
|
total_primes_found += 1;
|
|
|
|
let i = 2 * p;
|
|
|
|
|
|
|
|
while i < MAX_NUMBER_TO_CHECK {
|
|
|
|
prime_mask[i] = false;
|
|
|
|
i += p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print("Total " + total_primes_found + " primes.");
|
|
|
|
|