Algorithms · real, tested code

Check if a Number is Prime in Larzscript

Test primality, and generate a sieve of primes up to a limit.

mathx.is_prime() does real trial division (skipping even numbers past 2); mathx.sieve() runs a real Sieve of Eratosthenes for generating many primes at once.

larzscript pkg install mathx

Code

import "mathx" as mathx

print(mathx.is_prime(97))
print(mathx.is_prime(100))
print(mathx.sieve(50))
Output
true
false
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]