RosettaCodeData/Task/Population-count/00-TASK.txt

34 lines
2.0 KiB
Plaintext

The &nbsp; ''[[wp:Hamming weight|population count]]'' &nbsp; is the number of &nbsp; <big>'''1'''</big>s &nbsp; (ones) &nbsp; in the binary representation of a non-negative integer.
''Population count'' &nbsp; is also known as:
::::* &nbsp; ''pop count''
::::* &nbsp; ''popcount''
::::* &nbsp; ''sideways sum''
::::* &nbsp; ''bit summation''
::::* &nbsp; ''Hamming weight''
For example, &nbsp; <big>'''5'''</big> &nbsp; (which is &nbsp; <big>'''101'''</big> &nbsp; in binary) &nbsp; has a population count of &nbsp; <big>'''2'''</big>.
''[http://mathworld.wolfram.com/EvilNumber.html Evil numbers]'' &nbsp; are non-negative integers that have an &nbsp; ''even'' &nbsp; population count.
''[http://mathworld.wolfram.com/OdiousNumber.html Odious numbers]'' &nbsp; &nbsp; are &nbsp;positive integers that have an &nbsp; &nbsp;''odd'' &nbsp; 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 &nbsp; <big>'''0'''</big> &nbsp; (zero indexed).
:* display the &nbsp; ''pop count'' &nbsp; of the &nbsp; 1<sup>st</sup> &nbsp; thirty powers of &nbsp; <big>'''3'''</big> &nbsp; &nbsp; &nbsp; (<big>'''3<sup>0</sup>''', &nbsp; '''3<sup>1</sup>''', &nbsp; '''3<sup>2</sup>''', &nbsp; '''3<sup>3</sup>''', &nbsp; '''3<sup>4</sup>''', &nbsp; <b>∙∙∙</b> &nbsp; '''3<sup>29</sup>'''</big>).
:* display the &nbsp; 1<sup>st</sup> &nbsp; thirty &nbsp; &nbsp; ''evil'' &nbsp; &nbsp; numbers.
:* display the &nbsp; 1<sup>st</sup> &nbsp; thirty &nbsp; ''odious'' &nbsp; numbers.
* display each list of integers on one line &nbsp; (which may or may not include a title), &nbsp; each set of integers being shown should be properly identified.
;See also
* The On-Line Encyclopedia of Integer Sequences: &nbsp; [[oeis:A000120|A000120 population count]].
* The On-Line Encyclopedia of Integer Sequences: &nbsp; [[oeis:A000069|A000069 odious numbers]].
* The On-Line Encyclopedia of Integer Sequences: &nbsp; [[oeis:A001969|A001969 evil numbers]].
<br><br>