RosettaCodeData/Task/Population-count/Seed7/population-count.seed7
2023-07-01 13:44:08 -04:00

32 lines
723 B
Text

$ include "seed7_05.s7i";
const func integer: popcount (in integer: n) is
return card(bitset(n));
const proc: main is func
local
var integer: count is 0;
var integer: num is 0;
begin
for num range 0 to 29 do
write(popcount(3 ** num) <& " ");
end for;
writeln;
write("evil: ");
for num range 0 to integer.last until count >= 30 do
if not odd(popcount(num)) then
write(num <& " ");
incr(count);
end if;
end for;
writeln;
write("odious: ");
count := 0;
for num range 0 to integer.last until count >= 30 do
if odd(popcount(num)) then
write(num <& " ");
incr(count);
end if;
end for;
writeln;
end func;