Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Eliud's eggs exercise #1279

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 40 additions & 45 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,60 +42,60 @@
"slug": "lucians-luscious-lasagna",
"name": "Lucian's Luscious Lasagna",
"uuid": "3aa220cb-606f-45c5-9b7a-4bce0e4eb20d",
"prerequisites": [],
"status": "beta",
"concepts": [
"basics"
]
],
"prerequisites": [],
"status": "beta"
},
{
"slug": "temperature",
"name": "Temperature",
"uuid": "6ed15adb-f022-4bbd-bbb3-22845deabc91",
"concepts": [
"numbers"
],
"prerequisites": [
"basics"
],
"status": "beta",
"concepts": [
"numbers"
]
"status": "beta"
},
{
"slug": "pacman-rules",
"name": "Pac-Man Rules",
"uuid": "9050f8c3-9976-4c4d-93e7-c9c549b1c524",
"concepts": [
"booleans"
],
"prerequisites": [
"basics"
],
"status": "wip",
"concepts": [
"booleans"
]
"status": "wip"
},
{
"slug": "guessing-game",
"name": "Guessing Game",
"uuid": "fb9868eb-ce4f-4e6b-aa0d-b47d3451070f",
"concepts": [
"pattern-matching-literals"
],
"prerequisites": [
"numbers"
],
"status": "beta",
"concepts": [
"pattern-matching-literals"
]
"status": "beta"
},
{
"slug": "valentines-day",
"name": "Valentines Day",
"uuid": "537d8df3-0b12-4dbe-aa86-65ae79c4de0e",
"concepts": [
"algebraic-data-types"
],
"prerequisites": [
"pattern-matching-literals",
"numbers"
],
"status": "beta",
"concepts": [
"algebraic-data-types"
]
"status": "beta"
}
],
"practice": [
Expand Down Expand Up @@ -297,8 +297,7 @@
"uuid": "dde7cf64-7e3b-4e5c-8a65-5d639fa8a307",
"practices": [],
"prerequisites": [],
"difficulty": 5,
"topics": []
"difficulty": 5
},
{
"slug": "luhn",
Expand Down Expand Up @@ -331,17 +330,15 @@
"uuid": "821f2081-dfc2-40c6-8e12-2907daa04416",
"practices": [],
"prerequisites": [],
"difficulty": 7,
"topics": []
"difficulty": 7
},
{
"slug": "game-of-life",
"name": "Game of Life",
"uuid": "eb221634-15c6-463c-8268-54a3c3aa0c66",
"practices": [],
"prerequisites": [],
"difficulty": 7,
"topics": []
"difficulty": 7
},
{
"slug": "perfect-numbers",
Expand Down Expand Up @@ -496,8 +493,7 @@
"uuid": "00b6c83b-e652-4f71-a094-b3034f77fd7b",
"practices": [],
"prerequisites": [],
"difficulty": 4,
"topics": []
"difficulty": 4
},
{
"slug": "food-chain",
Expand Down Expand Up @@ -868,8 +864,7 @@
"uuid": "01401d15-6667-4f94-bcd2-ec5a70df1cc6",
"practices": [],
"prerequisites": [],
"difficulty": 4,
"topics": []
"difficulty": 4
},
{
"slug": "sieve",
Expand Down Expand Up @@ -926,8 +921,7 @@
"uuid": "78971281-153d-4bdc-8f90-4b7eded2b201",
"practices": [],
"prerequisites": [],
"difficulty": 8,
"topics": []
"difficulty": 8
},
{
"slug": "pov",
Expand Down Expand Up @@ -1042,8 +1036,7 @@
"uuid": "f49d76f7-f826-4b6a-a514-47af7e84144a",
"practices": [],
"prerequisites": [],
"difficulty": 6,
"topics": []
"difficulty": 6
},
{
"slug": "sgf-parsing",
Expand Down Expand Up @@ -1097,8 +1090,7 @@
"uuid": "7157a846-5846-47a4-97c2-daad7f763512",
"practices": [],
"prerequisites": [],
"difficulty": 3,
"topics": []
"difficulty": 3
},
{
"slug": "roman-numerals",
Expand Down Expand Up @@ -1302,7 +1294,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1312,7 +1303,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1322,7 +1312,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1332,7 +1321,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1342,7 +1330,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand Down Expand Up @@ -1377,6 +1364,14 @@
"topics": [
"strings"
]
},
{
"slug": "eliuds-eggs",
"name": "Eliud's Eggs",
"uuid": "73f0f60f-b4df-4384-adf1-4a03485459de",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
],
"foregone": [
Expand Down Expand Up @@ -1443,15 +1438,15 @@
}
],
"tags": [
"execution_mode/compiled",
"paradigm/declarative",
"paradigm/functional",
"typing/static",
"typing/strong",
"execution_mode/compiled",
"platform/windows",
"platform/mac",
"platform/linux",
"platform/mac",
"platform/windows",
"runtime/standalone_executable",
"typing/static",
"typing/strong",
"used_for/backends",
"used_for/financial_systems"
]
c0m3tx marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
8 changes: 8 additions & 0 deletions exercises/practice/eliuds-eggs/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Instructions

Your task is to count the number of 1 bits in the binary representation of a number.

## Restrictions

Keep your hands off that bit-count functionality provided by your standard library!
Solve this one yourself using other basic tools instead.
47 changes: 47 additions & 0 deletions exercises/practice/eliuds-eggs/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Introduction

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. Scan the potential egg-laying spots and mark down a `1` for an existing egg or a `0` for an empty spot.
2. Convert the number from binary to decimal.
3. Show the result on the display.

Example 1:

```text
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:

```text
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
```
24 changes: 24 additions & 0 deletions exercises/practice/eliuds-eggs/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"authors": [
"c0m3tx"
],
"contributors": [],
"files": {
"solution": [
"src/EliudsEggs.hs",
"package.yaml"
],
"test": [
"test/Tests.hs"
],
"example": [
".meta/examples/success-standard/src/EliudsEggs.hs"
],
"invalidator": [
"stack.yaml"
]
},
"blurb": "Help Eliud count the number of eggs in her chicken coop by counting the number of 1 bits in a binary representation.",
"source": "Christian Willner, Eric Willigers",
"source_url": "https://forum.exercism.org/t/new-exercise-suggestion-pop-count/7632/5"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: eliuds-eggs

dependencies:
- base

library:
exposed-modules: EliudsEggs
source-dirs: src

tests:
test:
main: Tests.hs
source-dirs: test
dependencies:
- eliuds-eggs
- hspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module EliudsEggs (eggCount) where

eggCount :: Int -> Int
eggCount 0 = 0
eggCount x | odd x = 1 + eggCount (x `div` 2)
eggCount x = eggCount (x `div` 2)
c0m3tx marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions exercises/practice/eliuds-eggs/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[559e789d-07d1-4422-9004-3b699f83bca3]
description = "0 eggs"

[97223282-f71e-490c-92f0-b3ec9e275aba]
description = "1 egg"

[1f8fd18f-26e9-4144-9a0e-57cdfc4f4ff5]
description = "4 eggs"

[0c18be92-a498-4ef2-bcbb-28ac4b06cb81]
description = "13 eggs"
21 changes: 21 additions & 0 deletions exercises/practice/eliuds-eggs/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: eliuds-eggs
version: 0.0.0.1

dependencies:
- base

library:
exposed-modules: EliudsEggs
source-dirs: src
ghc-options: -Wall
# dependencies:
# - foo # List here the packages you
# - bar # want to use in your solution.

tests:
test:
main: Tests.hs
source-dirs: test
dependencies:
- eliuds-eggs
- hspec
4 changes: 4 additions & 0 deletions exercises/practice/eliuds-eggs/src/EliudsEggs.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module EliudsEggs (eggCount) where

eggCount :: Int -> Int
eggCount = error "You need to implement this function"
c0m3tx marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions exercises/practice/eliuds-eggs/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resolver: lts-20.18
Loading
Loading