6 lines
128 B
Raku
6 lines
128 B
Raku
sub population-count(Int $n is copy where * >= 0) {
|
|
loop (my $c = 0; $n; $n +>= 1) {
|
|
$c += $n +& 1;
|
|
}
|
|
$c;
|
|
}
|