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