Skip to content

Commit 3a3f22b

Browse files
[ Implementation ] Eliud's Eggs (#739)
* [ Implementation ] Eliud's Eggs 💜²⁶ -- 🤝 https://forum.exercism.org/t/new-exercise-contributions/4077
1 parent a6beafd commit 3a3f22b

File tree

10 files changed

+188
-0
lines changed

10 files changed

+188
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,14 @@
719719
"practices": [],
720720
"prerequisites": [],
721721
"difficulty": 1
722+
},
723+
{
724+
"slug": "eliuds-eggs",
725+
"name": "Eliud's Eggs",
726+
"uuid": "cc172e3c-5537-4de8-9488-ef6db3d7d912",
727+
"practices": [],
728+
"prerequisites": [],
729+
"difficulty": 1
722730
}
723731
]
724732
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
![Seven individual nest boxes arranged in a row whose first, third, fourth and seventh nests each have a single egg.](https://assets.exercism.org/images/exercises/eliuds-eggs/example-1-coop.svg)
18+
19+
```text
20+
_ _ _ _ _ _ _
21+
|E| |E|E| | |E|
22+
```
23+
24+
### Resulting Binary
25+
26+
![1011001](https://assets.exercism.org/images/exercises/eliuds-eggs/example-1-binary.svg)
27+
28+
```text
29+
_ _ _ _ _ _ _
30+
|1|0|1|1|0|0|1|
31+
```
32+
33+
### Decimal number on the display
34+
35+
89
36+
37+
### Actual eggs in the coop
38+
39+
4
40+
41+
## Example 2
42+
43+
![Seven individual nest boxes arranged in a row where only the fourth nest has an egg.](https://assets.exercism.org/images/exercises/eliuds-eggs/example-2-coop.svg)
44+
45+
```text
46+
_ _ _ _ _ _ _
47+
| | | |E| | | |
48+
```
49+
50+
### Resulting Binary
51+
52+
![0001000](https://assets.exercism.org/images/exercises/eliuds-eggs/example-2-binary.svg)
53+
54+
```text
55+
_ _ _ _ _ _ _
56+
|0|0|0|1|0|0|0|
57+
```
58+
59+
### Decimal number on the display
60+
61+
16
62+
63+
### Actual eggs in the coop
64+
65+
1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"habere-et-dispertire"
4+
],
5+
"files": {
6+
"solution": [
7+
"lib/EliudsEggs.rakumod"
8+
],
9+
"test": [
10+
"t/eliuds-eggs.rakutest"
11+
],
12+
"example": [
13+
".meta/solutions/lib/EliudsEggs.rakumod"
14+
]
15+
},
16+
"blurb": "Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.",
17+
"source": "Christian Willner, Eric Willigers",
18+
"source_url": "https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5"
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
unit module EliudsEggs;
2+
3+
sub count-eggs ( $display ) is export {
4+
$display.base( 2 ).comb.Bag{ '1' };
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../t/eliuds-eggs.rakutest
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
properties:
2+
eggCount:
3+
test: |-
4+
sprintf(q :to 'END', %case<input><number>.Int, %case<expected>.Int, %case<description>.raku);
5+
cmp-ok(
6+
count-eggs(%s),
7+
"==",
8+
%s,
9+
%s,
10+
);
11+
END
12+
13+
14+
unit: module
15+
example: |-
16+
sub count-eggs ( $display ) is export {
17+
$display.base( 2 ).comb.Bag{ '1' };
18+
}
19+
20+
stub: |-
21+
sub count-eggs ( $display ) is export {
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[559e789d-07d1-4422-9004-3b699f83bca3]
13+
description = "0 eggs"
14+
15+
[97223282-f71e-490c-92f0-b3ec9e275aba]
16+
description = "1 egg"
17+
18+
[1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5]
19+
description = "4 eggs"
20+
21+
[0c18be92-a498-4ef2-bcbb-28ac4b06cb81]
22+
description = "13 eggs"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
unit module EliudsEggs;
2+
3+
sub count-eggs ( $display ) is export {
4+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env raku
2+
use Test;
3+
use lib $?FILE.IO.parent(2).add('lib');
4+
use EliudsEggs;
5+
6+
cmp-ok( # begin: 559e789d-07d1-4422-9004-3b699f83bca3
7+
count-eggs(0),
8+
"==",
9+
0,
10+
"0 eggs",
11+
); # end: 559e789d-07d1-4422-9004-3b699f83bca3
12+
13+
cmp-ok( # begin: 97223282-f71e-490c-92f0-b3ec9e275aba
14+
count-eggs(16),
15+
"==",
16+
1,
17+
"1 egg",
18+
); # end: 97223282-f71e-490c-92f0-b3ec9e275aba
19+
20+
cmp-ok( # begin: 1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5
21+
count-eggs(89),
22+
"==",
23+
4,
24+
"4 eggs",
25+
); # end: 1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5
26+
27+
cmp-ok( # begin: 0c18be92-a498-4ef2-bcbb-28ac4b06cb81
28+
count-eggs(2000000000),
29+
"==",
30+
13,
31+
"13 eggs",
32+
); # end: 0c18be92-a498-4ef2-bcbb-28ac4b06cb81
33+
34+
done-testing;

0 commit comments

Comments
 (0)