GCC: int__builtin_popcount(unsigned int x)
Returns the number of 1-bits in x.
Java: public static intbitCount(int i)
Returns the number of one-bits in the two’s complement binary representation of the specified int value. This function is sometimes referred to as the population count.
Haskell: popCount1:: v -> Count
The number of 1-bits in the value.
Python: int.bit_count()
Return the number of ones in the binary representation of the absolute value of the integer. This is also known as the population count.
x86: POPCNT
This instruction calculates the number of bits set to 1.
I believe @kytrinyx is asking that any new exercises be accompanied but a relatable story that makes the exercise more about solving something real world related and not purely programming oriented. You may want to add that to the proposal
A checkers program uses a binary number to remember which squares are occupied.
The 1’s bit is set if the first square is occupied, the 2’s bit is set if the second square is occupied, the 4’s bit is set if the third square is occupied, and so on.
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.
Eliudis 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:
Scan the potential egg-laying spots and mark down a 1 for an existing egg or a 0 for an empty spot.
Convert the number from binary to decimal
Show the result on the display
Example 1:
Chicken Coop:
_ _ _ _ _ _ _
|E| |E|E| | |E|
Resulting Binary:
1 0 1 1 0 0 1
Decimal number on the display:
89
Actual eggs in the coop:
4
Example 2:
Chicken Coop:
_ _ _ _ _ _ _ _
| | | |E| | | | |
Resulting Binary:
0 0 0 1 0 0 0 0
Decimal number on the display:
16
Actual eggs in the coop:
1
Maybe this will fare better if the egg is more of a cartoon style? Just a black oval shape outline and white inside similar to this: Egg icon PNG and SVG Vector Free Download ?
I like the art style. If we use an image, we should supply a good alt-text. I have no idea how the current “ascii art” fares with screen readers. Are there people here who can comment on that?
As for serving alt text with exercise icons, I think that would be a website change proposal, affecting all exercises. Perhaps start a separate forum thread.
I had some minor confusion related to this.
I’m plodding through WASM for November and saw I need to solve “pop-count” to get the badge but didn’t see that exercise listed. Discovered this thread and see the exercise has the new name “Eliud’s Eggs” while the pop-up text when I hover over the badge reads “Solve pop-count in …”. Same goes for the descriptive text in the Nibbly November post published at The #12in23 Challenge - still refers to Pop Count and not the new name.