Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
32
Task/Population-count/Pluto/population-count.pluto
Normal file
32
Task/Population-count/Pluto/population-count.pluto
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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(" "))
|
||||
Loading…
Add table
Add a link
Reference in a new issue