Description (from Rosetta Code)
| The population count is the number of 1s (ones) in the binary representation of a non-negative integer.
Population count is also known as pop count, popcount, sideways sum, and Hamming weight.
Evil numbers are non-negative integers that have an even population count.
Odious numbers are positive integers that have an odd population count.
Fōrmulæ has an integrated expression BitCount that counts the number of 1's of the binary representation of the number.
However, a function can also be written, as follows:
The plot of the population count of the numbers 0..256:
Case 1. Displaying the pop count of the 1st thirty powers of 3 (30, 31, 32, 33, 34 ∙∙∙ 329)
Case 2. Displaying the 1st thirty evil numbers
We need first a function to calculate the first numbers whose population count satisfies a given condition, passed as a lambda expression:
Calling the previous function with the criteria of being even numbers:
Case 3. Displaying the 1st thirty odious numbers
Calling the previous function with the criteria of being odd numbers: