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.
34 lines
496 B
34 lines
496 B
-- 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
|
|
|