Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Simple Lua primality test
--lua 5.3 local function isPrime(num) assert(math.type(num) == "integer", "argument is not an integer") assert(num >= 2, "argument must be 2 or greater") for i = 2, math.floor(math.sqrt(num)) do if num % i == 0 then return false end end return true end for i = 2, 1000 do if isPrime(i) then io.write(i, " ") end end local x = io.read("*n") io.write("\n\n", x, " is a prime: ", tostring(isPrime(x)))
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Monty Hall Problem Simulated
Key
Lua recursion with function
Binary to Integers / Integers to Binary
ROBLOX Ui Play Button
Hakusu
test
Reverse strings function - Lua
missing element
finding volume of pyramids (for me, but feel free to use)
Please log in to post a comment.