Population count: Difference between revisions
Content added Content deleted
Line 2,631: | Line 2,631: | ||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
=====Using just Count() and loops===== |
|||
<syntaxhighlight lang="m2000 interpreter"> |
<syntaxhighlight lang="m2000 interpreter"> |
||
Module Population_count{ |
Module Population_count{ |
||
Line 2,668: | Line 2,669: | ||
print "odious numbers:", array([])#str$() |
print "odious numbers:", array([])#str$() |
||
} |
} |
||
} |
|||
Population_count |
|||
</syntaxhighlight> |
|||
=====Using Generators===== |
|||
<syntaxhighlight lang="m2000 interpreter"> |
|||
Module Population_count{ |
|||
Count=lambda (x as long long)->{ |
|||
integer Count |
|||
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 |
|||
} |
|||
series3pow=lambda Count, i=0&& -> { |
|||
=count(3&&^i):i++ |
|||
} |
|||
seriesEvil=lambda Count, i=0&&-> { |
|||
while Count(i) mod 2=1{i++} |
|||
=i:i++ |
|||
} |
|||
seriesOdious=lambda Count, i=0&&-> { |
|||
while Count(i) mod 2=0{i++} |
|||
=i:i++ |
|||
} |
|||
Dim a(30)<<series3pow() |
|||
print "3^x population:", a()#str$() |
|||
Dim a(30)<<seriesEvil() |
|||
print "evil numbers:", a()#str$() |
|||
Dim a(30)<<seriesOdious() |
|||
print "odious numbers:", a()#str$() |
|||
} |
} |
||
Population_count |
Population_count |