RosettaCodeData/Task/Happy-numbers/Pluto/happy-numbers.pluto
2026-04-30 12:34:36 -04:00

26 lines
474 B
Text

local function happy(n)
local m = {}
while n > 1 do
m[n] = true
local x = n
n = 0
while x > 0 do
local d = x % 10
n += d * d
x //= 10
end
if m[n] then return false end -- m[n] will be nil if 'n' is not a key
end
return true
end
local found = 0
local n = 1
while found < 8 do
if happy(n) then
io.write($"{n} ")
found += 1
end
n += 1
end
print()