RosettaCodeData/Task/Perfect-numbers/Lua/perfect-numbers.lua

11 lines
219 B
Lua
Raw Permalink Normal View History

2026-04-30 12:34:36 -04:00
local function isPerfect(x)
2023-07-01 11:58:00 -04:00
local sum = 0
for i = 1, x-1 do
2026-04-30 12:34:36 -04:00
if x % i == 0 then sum = sum + i end
2023-07-01 11:58:00 -04:00
end
return sum == x
end
2026-04-30 12:34:36 -04:00
for i = 1, 10000 do
if isPerfect( i ) then io.write( " "..i ) end
end