34 lines
2.0 KiB
Plaintext
34 lines
2.0 KiB
Plaintext
The ''[[wp:Hamming weight|population count]]'' is the number of <big>'''1'''</big>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, <big>'''5'''</big> (which is <big>'''101'''</big> in binary) has a population count of <big>'''2'''</big>.
|
|
|
|
|
|
''[http://mathworld.wolfram.com/EvilNumber.html Evil numbers]'' are non-negative integers that have an ''even'' population count.
|
|
|
|
''[http://mathworld.wolfram.com/OdiousNumber.html 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 <big>'''0'''</big> (zero indexed).
|
|
:* display the ''pop count'' of the 1<sup>st</sup> thirty powers of <big>'''3'''</big> (<big>'''3<sup>0</sup>''', '''3<sup>1</sup>''', '''3<sup>2</sup>''', '''3<sup>3</sup>''', '''3<sup>4</sup>''', <b>∙∙∙</b> '''3<sup>29</sup>'''</big>).
|
|
:* display the 1<sup>st</sup> thirty ''evil'' numbers.
|
|
:* display the 1<sup>st</sup> 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: [[oeis:A000120|A000120 population count]].
|
|
* The On-Line Encyclopedia of Integer Sequences: [[oeis:A000069|A000069 odious numbers]].
|
|
* The On-Line Encyclopedia of Integer Sequences: [[oeis:A001969|A001969 evil numbers]].
|
|
<br><br>
|
|
|