RosettaCodeData/Task/List-comprehensions/Pluto/list-comprehensions.pluto
2026-04-30 12:34:36 -04:00

16 lines
431 B
Text

local function pythagorean_triples(n)
for x = 1, n - 2 do
for y = x + 1, n - 1 do
for z = y + 1, n do
if x * x + y * y == z * z then coroutine.yield({x, y, z}) end
end
end
end
end
local n = 20
local co = coroutine.create(pythagorean_triples)
while true do
local _, res = coroutine.resume(co, n)
if res then print($"\{{res:concat(", ")}}") else break end
end