Your friend Eliud inherited a farm from her grandma Tigist. Her granny was an inventor and had a tendency to build things in an overly complicated manner. The chicken coop has a digital display showing an encoded number representing the positions of all eggs that could be picked up.
Eliud is asking you to write a program that shows the actual number of eggs in the coop.
The position information encoding is calculated as follows:
1
for an existing egg or a 0
for an empty spot. _ _ _ _ _ _ _
|E| |E|E| | |E|
_ _ _ _ _ _ _
|1|0|1|1|0|0|1|
89
4
_ _ _ _ _ _ _
| | | |E| | | |
_ _ _ _ _ _ _
|0|0|0|1|0|0|0|
16
1
Your task is to count the number of 1 bits in the binary representation of a number.
Keep your hands off that bit-count functionality provided by your standard library! Solve this one yourself using other basic tools instead.
The instructions above are synchronized with a shared repository to ensure consistency across all language tracks. This appendix provides additional clarification or modifies the instructions as needed to better align with the goals of the Clojure track.
It is important not to use existing built-in functions with similar functionality to the function you are implementing, as doing so would diminish the intended learning value of the exercise.
In Clojure, there is no built-in function to count the number of bits in a number, so you may use any Clojure function in your implementation.
However, Java does include a function for this purpose: bitCount
.
Sign up to Exercism to learn and master Clojure with 12 concepts, 100 exercises, and real human mentoring, all for free.