File tree Expand file tree Collapse file tree 4 files changed +100
-0
lines changed Expand file tree Collapse file tree 4 files changed +100
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "exercise" : " pop-count" ,
3+ "cases" : [
4+ {
5+ "uuid" : " 559e789d-07d1-4422-9004-3b699f83bca3" ,
6+ "description" : " 0 eggs" ,
7+ "property" : " eggCount" ,
8+ "input" : {
9+ "number" : 0
10+ },
11+ "expected" : 0
12+ },
13+ {
14+ "uuid" : " 97223282-f71e-490c-92f0-b3ec9e275aba" ,
15+ "description" : " 1 egg" ,
16+ "property" : " eggCount" ,
17+ "input" : {
18+ "number" : 16
19+ },
20+ "expected" : 1
21+ },
22+ {
23+ "uuid" : " 1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5" ,
24+ "description" : " 4 eggs" ,
25+ "property" : " eggCount" ,
26+ "input" : {
27+ "number" : 89
28+ },
29+ "expected" : 4
30+ },
31+ {
32+ "uuid" : " 0c18be92-a498-4ef2-bcbb-28ac4b06cb81" ,
33+ "description" : " 13 eggs" ,
34+ "property" : " eggCount" ,
35+ "input" : {
36+ "number" : 2000000000
37+ },
38+ "expected" : 13
39+ }
40+ ]
41+ }
Original file line number Diff line number Diff line change 1+ # Instructions
2+
3+ Your task is to count the number of 1 bits in the binary representation of a number.
4+
5+ ## Restrictions
6+
7+ Keep your hands off that bit-count functionality provided by your standard library!
8+ Solve this one yourself using other basic tools instead.
Original file line number Diff line number Diff line change 1+ # Introduction
2+
3+ Your friend Eliud inherited a farm from her grandma Tigist.
4+ Her granny was an inventor and had a tendency to build things in an overly complicated manner.
5+ The chicken coop has a digital display showing an encoded number representing the positions of all eggs that could be picked up.
6+
7+ Eliud is asking you to write a program that shows the actual number of eggs in the coop.
8+
9+ The position information encoding is calculated as follows:
10+
11+ 1 . Scan the potential egg-laying spots and mark down a ` 1 ` for an existing egg or a ` 0 ` for an empty spot.
12+ 2 . Convert the number from binary to decimal.
13+ 3 . Show the result on the display.
14+
15+ Example 1:
16+
17+ ``` text
18+ Chicken Coop:
19+ _ _ _ _ _ _ _
20+ |E| |E|E| | |E|
21+
22+ Resulting Binary:
23+ 1 0 1 1 0 0 1
24+
25+ Decimal number on the display:
26+ 89
27+
28+ Actual eggs in the coop:
29+ 4
30+ ```
31+
32+ Example 2:
33+
34+ ``` text
35+ Chicken Coop:
36+ _ _ _ _ _ _ _ _
37+ | | | |E| | | | |
38+
39+ Resulting Binary:
40+ 0 0 0 1 0 0 0 0
41+
42+ Decimal number on the display:
43+ 16
44+
45+ Actual eggs in the coop:
46+ 1
47+ ```
Original file line number Diff line number Diff line change 1+ title = " Pop Count"
2+ blurb = " Count the 1 bits in a number"
3+ source = " Christian Willner, Eric Willigers"
4+ source_url = " https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5"
You can’t perform that action at this time.
0 commit comments