RosettaCodeData/Task/Population-count/Pluto/population-count.pluto
2026-04-30 12:34:36 -04:00

32 lines
633 B
Text

local function popcount(n)
local count = 0
while n != 0 do
n = n & (n - 1)
count += 1
end
return count
end
print("The population count of the first 30 powers of 3 is:")
local p3 = 1
for i = 0, 29 do
io.write($"{popcount(p3)} ")
p3 *= 3
end
local odious = {}
print("\n\nThe first 30 evil numbers are:")
local count = 0
local n = 0
while count < 30 do
local pc = popcount(n)
if pc % 2 == 0 then
io.write($"{n} ")
count += 1
else
odious:insert(n)
end
n += 1
end
odious:insert(n)
print("\n\nThe first 30 odious numbers are:")
print(odious:concat(" "))