user
The   *population count*   is the number of   **1**s   (ones)   in the binary representation of a non-negative integer.

*Population count*   is also known as:

:   :   :   :   * *pop count*
                * *popcount*
                * *sideways sum*
                * *bit summation*
                * *Hamming weight*

For example,   **5**   (which is   **101**   in binary)   has a population count of   **2**.

*Evil numbers*   are non-negative integers that have an   *even*   population count.

*Odious numbers*     are  positive integers that have an    *odd*   population count.

Task

* write a function (or routine) to return the population count of a non-negative integer.
* all computation of the lists below should start with   **0**   (zero indexed).

:   * display the   *pop count*   of the   1st   thirty powers of   **3**       (**30**,   **31**,   **32**,   **33**,   **34**,   **∙∙∙**   **329**).
    * display the   1st   thirty     *evil*     numbers.
    * display the   1st   thirty   *odious*   numbers.

* display each list of integers on one line   (which may or may not include a title),   each set of integers being shown should be properly identified.

See also

* The On-Line Encyclopedia of Integer Sequences:   A000120 population count.
* The On-Line Encyclopedia of Integer Sequences:   A000069 odious numbers.
* The On-Line Encyclopedia of Integer Sequences:   A001969 evil numbers.
assistant
(formerly Perl 6)

```
sub population-count(Int $n where * >= 0) { [+] $n.base(2).comb }

say map &population-count, 3 «**« ^30;
say "Evil: ", (grep { population-count($_) %% 2 }, 0 .. *)[^30];
say "Odious: ", (grep { population-count($_)  % 2 }, 0 .. *)[^30];

```

Output:

```
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
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
```

That's the convenient way to write it, but the following avoids string processing and is therefore about twice as fast:

```
sub population-count(Int $n is copy where * >= 0) { 
    loop (my $c = 0; $n; $n +>= 1) { 
        $c += $n +& 1; 
    } 
    $c;
}

```