Population count: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Miranda) |
No edit summary |
||
Line 2,628: | Line 2,628: | ||
Evil: 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 |
Evil: 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 |
||
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> |
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|M2000 Interpreter}}== |
|||
<syntaxhighlight lang="m2000 interpreter"> |
|||
Module Population_count{ |
|||
Function Count(x as long long) { |
|||
Local integer Count |
|||
Local long long m=x |
|||
m|div 0x1_0000_0000&& |
|||
x|mod 0x1_0000_0000&& |
|||
While x<>0& |
|||
x=Binary.And(X, X-1&&) |
|||
Count++ |
|||
End While |
|||
x=m |
|||
While x<>0& |
|||
x=Binary.And(X, X-1&&) |
|||
Count++ |
|||
End While |
|||
=Count |
|||
} |
|||
long long i, b=3 |
|||
stack new { |
|||
for i=0 to 29 |
|||
Data count(b^i) |
|||
next |
|||
print array([])#str$() |
|||
i=0: b=0 |
|||
while i<30 |
|||
if Count(b) mod 2=0 then data b:i++ |
|||
b++ |
|||
end while |
|||
print array([])#str$() |
|||
i=0: b=0 |
|||
while i<30 |
|||
if Count(b) mod 2=1 then data b:i++ |
|||
b++ |
|||
end while |
|||
print array([])#str$() |
|||
} |
|||
} |
|||
Population_count |
|||
</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|MAD}}== |
=={{header|MAD}}== |