RosettaCodeData/Task/Loops-Increment-loop-index-within-loop-body/Pluto/loops-increment-loop-index-within-loop-body.pluto
2025-08-11 18:05:26 -07:00

27 lines
663 B
Text

local function is_prime(n)
assert(n % 1 == 0, "Argument must be an integer.")
if n < 2 then return false end
if n % 2 == 0 then return n == 2 end
if n % 3 == 0 then return n == 3 end
local d = 5
while d * d <= n do
if n % d == 0 then return false end
d += 2
if n % d == 0 then return false end
d += 4
end
return true
end
local count = 0
local i = 42
while count < 42 do
if is_prime(i) then
++count
local str1 = string.format("%2d", count)
local str2 = string.format("%18s", string.formatint(i))
print($"{str1}: {str2}")
i = 2 * i - 1
end
++i
end