29 lines
693 B
Text
29 lines
693 B
Text
local function powers(n)
|
|
local i = 0
|
|
while true do
|
|
coroutine.yield(i ** n)
|
|
i += 1
|
|
end
|
|
end
|
|
|
|
local function squares_not_cubes()
|
|
local cosq = coroutine.create(powers)
|
|
local cocu = coroutine.create(powers)
|
|
local cube = 0
|
|
while true do
|
|
local _, square = coroutine.resume(cosq, 2)
|
|
while cube < square do
|
|
_, cube = coroutine.resume(cocu, 3)
|
|
end
|
|
if cube != square then coroutine.yield(square) end
|
|
end
|
|
end
|
|
|
|
local co = coroutine.create(squares_not_cubes)
|
|
local count = 0
|
|
while count < 30 do
|
|
local _, square = coroutine.resume(co)
|
|
count += 1
|
|
if count > 20 then io.write($"{square} ") end
|
|
end
|
|
print()
|