Population count: Difference between revisions

add SETL
(add SETL)
Line 4,068:
odious: 1 2 4 7 8 11 13 14 16 19 21 22 25 26 28 31 32 35 37 38 41 42 44 47 49 50 52 55 56 59 </pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program population_count;
print([popcount(3**n) : n in [0..29]]);
print([n : n in [0..59] | evil n]);
print([n : n in [0..59] | odious n]);
 
op evil(n);
return even popcount n;
end op;
 
op odious(n);
return odd popcount n;
end op;
 
op popcount(n);
return +/[[n mod 2, n div:=2](1) : until n=0];
end op;
end program;</syntaxhighlight>
{{out}}
<pre>[1 2 2 4 3 6 6 5 6 8 9 13 10 11 14 15 11 14 14 17 17 20 19 22 16 18 24 30 25 25]
[0 3 5 6 9 10 12 15 17 18 20 23 24 27 29 30 33 34 36 39 40 43 45 46 48 51 53 54 57 58]
[1 2 4 7 8 11 13 14 16 19 21 22 25 26 28 31 32 35 37 38 41 42 44 47 49 50 52 55 56 59]</pre>
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func population_count(n) { n.as_bin.count('1') }
2,094

edits