Skip to content

Commit 0a87aa5

Browse files
Add eliuds-eggs exercise (#1290)
1 parent 10906a9 commit 0a87aa5

File tree

12 files changed

+182
-3
lines changed

12 files changed

+182
-3
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,14 @@
21412141
"practices": [],
21422142
"prerequisites": [],
21432143
"difficulty": 1
2144+
},
2145+
{
2146+
"slug": "eliuds-eggs",
2147+
"name": "Eliud's Eggs",
2148+
"uuid": "d5761ed1-a342-45eb-a2b3-95c7bc175046",
2149+
"practices": [],
2150+
"prerequisites": [],
2151+
"difficulty": 2
21442152
}
21452153
],
21462154
"foregone": [

exercises/Exercises.sln

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ResistorColorDuo", "practic
285285
EndProject
286286
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SquareRoot", "practice\square-root\SquareRoot.fsproj", "{C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}"
287287
EndProject
288+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "EliudsEggs", "practice\eliuds-eggs\EliudsEggs.fsproj", "{9DB2B6C7-E5A4-4AE0-9892-643BEB5F0493}"
289+
EndProject
288290
Global
289291
GlobalSection(SolutionConfigurationPlatforms) = preSolution
290292
Debug|Any CPU = Debug|Any CPU
@@ -848,11 +850,12 @@ Global
848850
{D7E215C6-4EE6-41AB-BD80-F126C50A590E}.Release|Any CPU.Build.0 = Release|Any CPU
849851
{C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
850852
{C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Debug|Any CPU.Build.0 = Debug|Any CPU
851-
{C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Release|Any CPU.ActiveCfg = Release|Any CPU
852853
{C41EB0DE-54C9-4673-8B8B-E9AA43DF3746}.Release|Any CPU.Build.0 = Release|Any CPU
854+
{9DB2B6C7-E5A4-4AE0-9892-643BEB5F0493}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
855+
{9DB2B6C7-E5A4-4AE0-9892-643BEB5F0493}.Debug|Any CPU.Build.0 = Debug|Any CPU
856+
{9DB2B6C7-E5A4-4AE0-9892-643BEB5F0493}.Release|Any CPU.Build.0 = Release|Any CPU
853857
EndGlobalSection
854858
GlobalSection(NestedProjects) = preSolution
855-
{9815492D-D8F9-439C-B73C-711693755626} = {9D239135-8242-4AC0-94AE-7CCD8408B531}
856859
{5C7A1C6C-25A7-4D4B-89E6-ABE1A3D839B2} = {9D239135-8242-4AC0-94AE-7CCD8408B531}
857860
{EAC7B507-0EB0-4D83-9EF0-9421FA2A2A74} = {9D239135-8242-4AC0-94AE-7CCD8408B531}
858861
{0F831DDE-1EBF-485D-8517-4EA037EC6FD7} = {9D239135-8242-4AC0-94AE-7CCD8408B531}
@@ -991,5 +994,5 @@ Global
991994
{6D2CFE86-D6B2-4820-B3D8-62255BF94DCD} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
992995
{D7E215C6-4EE6-41AB-BD80-F126C50A590E} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
993996
{C41EB0DE-54C9-4673-8B8B-E9AA43DF3746} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
997+
{9DB2B6C7-E5A4-4AE0-9892-643BEB5F0493} = {29984DF2-2734-483C-BC7D-F6D41599DACD}
994998
EndGlobalSection
995-
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"fantomas-tool": {
6+
"version": "4.7.9",
7+
"commands": [
8+
"fantomas"
9+
]
10+
}
11+
}
12+
}
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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module EliudsEggs
2+
3+
let eggCount n =
4+
let rec loop m count =
5+
match m with
6+
| 0 -> count
7+
| _ -> loop (m >>> 1) (count + if m &&& 1 = 0 then 0 else 1)
8+
9+
loop n 0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"erikschierboom"
4+
],
5+
"files": {
6+
"solution": [
7+
"EliudsEggs.fs"
8+
],
9+
"test": [
10+
"EliudsEggsTests.fs"
11+
],
12+
"example": [
13+
".meta/Example.fs"
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: 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module EliudsEggs
2+
3+
let eggCount n = failwith "Please implement the 'eggCount' function"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<IsPackable>false</IsPackable>
5+
<GenerateProgramFile>false</GenerateProgramFile>
6+
<IsTestProject>true</IsTestProject>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="EliudsEggs.fs" />
10+
<Compile Include="EliudsEggsTests.fs" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<PackageReference Include="Exercism.Tests" Version="0.1.0-beta1" />
14+
<PackageReference Include="FsUnit.xUnit" Version="4.0.4" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
16+
<PackageReference Include="xunit" Version="2.4.1" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
<PrivateAssets>all</PrivateAssets>
20+
</PackageReference>
21+
</ItemGroup>
22+
</Project>

0 commit comments

Comments
 (0)