38 lines
740 B
Text
38 lines
740 B
Text
local int = require "int"
|
|
|
|
local function is_emirp(n)
|
|
if !int.isprime(n) then return false end
|
|
local ns = tostring(n)
|
|
local rs = ns:reverse()
|
|
local r = tonumber(rs)
|
|
if r == n then return false end
|
|
if int.isprime(r) then return true end
|
|
return false
|
|
end
|
|
|
|
print("The first 20 emirps are:")
|
|
local count = 0
|
|
local i = 3
|
|
while count < 20 do
|
|
if is_emirp(i) then
|
|
count += 1
|
|
io.write($"{i} ")
|
|
end
|
|
i += 2
|
|
end
|
|
|
|
print("\n\nThe emirps between 7,700 and 8,000 are:")
|
|
i = 7701
|
|
while i < 8000 do
|
|
if is_emirp(i) then io.write($"{i} ") end
|
|
i += 2
|
|
end
|
|
|
|
io.write("\n\nThe 10,000th emirp is ")
|
|
count = 0
|
|
i = 1
|
|
while count < 10000 do
|
|
i += 2
|
|
if is_emirp(i) then count += 1 end
|
|
end
|
|
print(i)
|