mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
23 lines
319 B
Plaintext
23 lines
319 B
Plaintext
|
|
## Prime numbers.
|
|
|
|
res = ''
|
|
|
|
def is_prime(n)
|
|
if n < 2 then return false end
|
|
for i in 2..n
|
|
if n % i == 0 then return false end
|
|
end
|
|
return true
|
|
end
|
|
|
|
def get_all_primes(n)
|
|
for i in 0..n
|
|
if is_prime(i)
|
|
res += to_string(i) + ' '
|
|
end
|
|
end
|
|
end
|
|
|
|
get_all_primes(20)
|
|
assert(res == '2 3 5 7 11 13 17 19 ') |