diff --git a/config.json b/config.json index 145ade90f..e36a8aec6 100644 --- a/config.json +++ b/config.json @@ -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": [ @@ -297,8 +297,7 @@ "uuid": "dde7cf64-7e3b-4e5c-8a65-5d639fa8a307", "practices": [], "prerequisites": [], - "difficulty": 5, - "topics": [] + "difficulty": 5 }, { "slug": "luhn", @@ -331,8 +330,7 @@ "uuid": "821f2081-dfc2-40c6-8e12-2907daa04416", "practices": [], "prerequisites": [], - "difficulty": 7, - "topics": [] + "difficulty": 7 }, { "slug": "game-of-life", @@ -340,8 +338,7 @@ "uuid": "eb221634-15c6-463c-8268-54a3c3aa0c66", "practices": [], "prerequisites": [], - "difficulty": 7, - "topics": [] + "difficulty": 7 }, { "slug": "perfect-numbers", @@ -496,8 +493,7 @@ "uuid": "00b6c83b-e652-4f71-a094-b3034f77fd7b", "practices": [], "prerequisites": [], - "difficulty": 4, - "topics": [] + "difficulty": 4 }, { "slug": "food-chain", @@ -868,8 +864,7 @@ "uuid": "01401d15-6667-4f94-bcd2-ec5a70df1cc6", "practices": [], "prerequisites": [], - "difficulty": 4, - "topics": [] + "difficulty": 4 }, { "slug": "sieve", @@ -926,8 +921,7 @@ "uuid": "78971281-153d-4bdc-8f90-4b7eded2b201", "practices": [], "prerequisites": [], - "difficulty": 8, - "topics": [] + "difficulty": 8 }, { "slug": "pov", @@ -1042,8 +1036,7 @@ "uuid": "f49d76f7-f826-4b6a-a514-47af7e84144a", "practices": [], "prerequisites": [], - "difficulty": 6, - "topics": [] + "difficulty": 6 }, { "slug": "sgf-parsing", @@ -1097,8 +1090,7 @@ "uuid": "7157a846-5846-47a4-97c2-daad7f763512", "practices": [], "prerequisites": [], - "difficulty": 3, - "topics": [] + "difficulty": 3 }, { "slug": "roman-numerals", @@ -1302,7 +1294,6 @@ "practices": [], "prerequisites": [], "difficulty": 1, - "topics": null, "status": "deprecated" }, { @@ -1312,7 +1303,6 @@ "practices": [], "prerequisites": [], "difficulty": 1, - "topics": null, "status": "deprecated" }, { @@ -1322,7 +1312,6 @@ "practices": [], "prerequisites": [], "difficulty": 1, - "topics": null, "status": "deprecated" }, { @@ -1332,7 +1321,6 @@ "practices": [], "prerequisites": [], "difficulty": 1, - "topics": null, "status": "deprecated" }, { @@ -1342,7 +1330,6 @@ "practices": [], "prerequisites": [], "difficulty": 1, - "topics": null, "status": "deprecated" }, { @@ -1377,6 +1364,14 @@ "topics": [ "strings" ] + }, + { + "slug": "eliuds-eggs", + "name": "Eliud's Eggs", + "uuid": "73f0f60f-b4df-4384-adf1-4a03485459de", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ], "foregone": [ @@ -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" ] diff --git a/exercises/practice/eliuds-eggs/.docs/instructions.md b/exercises/practice/eliuds-eggs/.docs/instructions.md new file mode 100644 index 000000000..b0c2df593 --- /dev/null +++ b/exercises/practice/eliuds-eggs/.docs/instructions.md @@ -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. diff --git a/exercises/practice/eliuds-eggs/.docs/introduction.md b/exercises/practice/eliuds-eggs/.docs/introduction.md new file mode 100644 index 000000000..49eaffd8b --- /dev/null +++ b/exercises/practice/eliuds-eggs/.docs/introduction.md @@ -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 +``` diff --git a/exercises/practice/eliuds-eggs/.meta/config.json b/exercises/practice/eliuds-eggs/.meta/config.json new file mode 100644 index 000000000..6fa6e7d90 --- /dev/null +++ b/exercises/practice/eliuds-eggs/.meta/config.json @@ -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" +} diff --git a/exercises/practice/eliuds-eggs/.meta/examples/success-standard/package.yaml b/exercises/practice/eliuds-eggs/.meta/examples/success-standard/package.yaml new file mode 100644 index 000000000..8ed328b33 --- /dev/null +++ b/exercises/practice/eliuds-eggs/.meta/examples/success-standard/package.yaml @@ -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 diff --git a/exercises/practice/eliuds-eggs/.meta/examples/success-standard/src/EliudsEggs.hs b/exercises/practice/eliuds-eggs/.meta/examples/success-standard/src/EliudsEggs.hs new file mode 100644 index 000000000..b66fb44f5 --- /dev/null +++ b/exercises/practice/eliuds-eggs/.meta/examples/success-standard/src/EliudsEggs.hs @@ -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) diff --git a/exercises/practice/eliuds-eggs/.meta/tests.toml b/exercises/practice/eliuds-eggs/.meta/tests.toml new file mode 100644 index 000000000..e11683c2e --- /dev/null +++ b/exercises/practice/eliuds-eggs/.meta/tests.toml @@ -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" diff --git a/exercises/practice/eliuds-eggs/package.yaml b/exercises/practice/eliuds-eggs/package.yaml new file mode 100644 index 000000000..35058ddf3 --- /dev/null +++ b/exercises/practice/eliuds-eggs/package.yaml @@ -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 diff --git a/exercises/practice/eliuds-eggs/src/EliudsEggs.hs b/exercises/practice/eliuds-eggs/src/EliudsEggs.hs new file mode 100644 index 000000000..03bed2a51 --- /dev/null +++ b/exercises/practice/eliuds-eggs/src/EliudsEggs.hs @@ -0,0 +1,4 @@ +module EliudsEggs (eggCount) where + +eggCount :: Int -> Int +eggCount = error "You need to implement this function" diff --git a/exercises/practice/eliuds-eggs/stack.yaml b/exercises/practice/eliuds-eggs/stack.yaml new file mode 100644 index 000000000..115878212 --- /dev/null +++ b/exercises/practice/eliuds-eggs/stack.yaml @@ -0,0 +1 @@ +resolver: lts-20.18 diff --git a/exercises/practice/eliuds-eggs/test/Tests.hs b/exercises/practice/eliuds-eggs/test/Tests.hs new file mode 100644 index 000000000..93c6819eb --- /dev/null +++ b/exercises/practice/eliuds-eggs/test/Tests.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE RecordWildCards #-} + +import Data.Foldable (for_) +import EliudsEggs (eggCount) +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFailFast, defaultConfig, hspecWith) + +main :: IO () +main = hspecWith defaultConfig {configFailFast = True} specs + +specs :: Spec +specs = describe "eggCount" $ for_ cases test + where + test Case {..} = it description assertion + where + assertion = expression `shouldBe` output + expression = eggCount input + +data Case = Case + { description :: String, + input :: Int, + output :: Int + } + +cases :: [Case] +cases = + [ Case + { description = "0 eggs", + input = 0, + output = 0 + }, + Case + { description = "1 egg", + input = 16, + output = 1 + }, + Case + { description = "4 eggs", + input = 89, + output = 4 + }, + Case + { description = "13 eggs", + input = 2000000000, + output = 13 + } + ]