You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
481 B

-- Lua 5 version of a Prime Number Finder
-- haplo@mindstab.net
function primes(max)
cnt = 3
while cnt <= max do
sq = math.sqrt(cnt)
isp = 1
i = 3
while i <= sq and isp ~= 0 do
isp = math.mod(cnt, i)
i = i+2
end
if isp ~= 0 then
print(cnt)
end
cnt = cnt + 2
end
end
argc = table.getn(arg)
if argc < 1 then
print("Usage: primeslua [Max Num]")
else
max = tonumber(arg[1])
if not max then
print("Invalid Max Num")
else
primes(max)
end
end