From a2c69dc21529c1463c62ecb2b998f27e43c3eb15 Mon Sep 17 00:00:00 2001 From: Jie Date: Sun, 21 Jul 2024 18:30:12 +0900 Subject: [PATCH] Add practice exercise `kindergarten-garden` (#704) --- config.json | 15 +++ .../kindergarten-garden/.docs/instructions.md | 56 ++++++++++ .../kindergarten-garden/.docs/introduction.md | 6 ++ .../kindergarten-garden/.meta/config.json | 19 ++++ .../.meta/src/KindergartenGarden.example.elm | 101 +++++++++++++++++ .../kindergarten-garden/.meta/tests.toml | 61 +++++++++++ .../practice/kindergarten-garden/elm.json | 29 +++++ .../src/KindergartenGarden.elm | 28 +++++ .../kindergarten-garden/tests/Tests.elm | 102 ++++++++++++++++++ 9 files changed, 417 insertions(+) create mode 100644 exercises/practice/kindergarten-garden/.docs/instructions.md create mode 100644 exercises/practice/kindergarten-garden/.docs/introduction.md create mode 100644 exercises/practice/kindergarten-garden/.meta/config.json create mode 100644 exercises/practice/kindergarten-garden/.meta/src/KindergartenGarden.example.elm create mode 100644 exercises/practice/kindergarten-garden/.meta/tests.toml create mode 100644 exercises/practice/kindergarten-garden/elm.json create mode 100644 exercises/practice/kindergarten-garden/src/KindergartenGarden.elm create mode 100644 exercises/practice/kindergarten-garden/tests/Tests.elm diff --git a/config.json b/config.json index b0532a04..fb35b189 100644 --- a/config.json +++ b/config.json @@ -1322,6 +1322,21 @@ "records" ], "difficulty": 7 + }, + { + "slug": "kindergarten-garden", + "name": "Kindergarten Garden", + "uuid": "ca24f48c-c38a-4ffa-97de-37f12d6c0e0b", + "practices": [ + "pattern-matching" + ], + "prerequisites": [ + "strings", + "lists", + "pattern-matching", + "custom-types" + ], + "difficulty": 4 } ] }, diff --git a/exercises/practice/kindergarten-garden/.docs/instructions.md b/exercises/practice/kindergarten-garden/.docs/instructions.md new file mode 100644 index 00000000..6fe11a58 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.docs/instructions.md @@ -0,0 +1,56 @@ +# Instructions + +Your task is to, given a diagram, determine which plants each child in the kindergarten class is responsible for. + +There are 12 children in the class: + +- Alice, Bob, Charlie, David, Eve, Fred, Ginny, Harriet, Ileana, Joseph, Kincaid, and Larry. + +Four different types of seeds are planted: + +| Plant | Diagram encoding | +| ------ | ---------------- | +| Grass | G | +| Clover | C | +| Radish | R | +| Violet | V | + +Each child gets four cups, two on each row: + +```text +[window][window][window] +........................ # each dot represents a cup +........................ +``` + +Their teacher assigns cups to the children alphabetically by their names, which means that Alice comes first and Larry comes last. + +Here is an example diagram representing Alice's plants: + +```text +[window][window][window] +VR...................... +RG...................... +``` + +In the first row, nearest the windows, she has a violet and a radish. +In the second row she has a radish and some grass. + +Your program will be given the plants from left-to-right starting with the row nearest the windows. +From this, it should be able to determine which plants belong to each student. + +For example, if it's told that the garden looks like so: + +```text +[window][window][window] +VRCGVVRVCGGCCGVRGCVCGCGV +VRCCCGCRRGVCGCRVVCVGCGCV +``` + +Then if asked for Alice's plants, it should provide: + +- Violets, radishes, violets, radishes + +While asking for Bob's plants would yield: + +- Clover, grass, clover, clover diff --git a/exercises/practice/kindergarten-garden/.docs/introduction.md b/exercises/practice/kindergarten-garden/.docs/introduction.md new file mode 100644 index 00000000..5ad97d23 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.docs/introduction.md @@ -0,0 +1,6 @@ +# Introduction + +The kindergarten class is learning about growing plants. +The teacher thought it would be a good idea to give the class seeds to plant and grow in the dirt. +To this end, the children have put little cups along the window sills and planted one type of plant in each cup. +The children got to pick their favorites from four available types of seeds: grass, clover, radishes, and violets. diff --git a/exercises/practice/kindergarten-garden/.meta/config.json b/exercises/practice/kindergarten-garden/.meta/config.json new file mode 100644 index 00000000..ae322864 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "jiegillet" + ], + "files": { + "solution": [ + "src/KindergartenGarden.elm" + ], + "test": [ + "tests/Tests.elm" + ], + "example": [ + ".meta/src/KindergartenGarden.example.elm" + ] + }, + "blurb": "Given a diagram, determine which plants each child in the kindergarten class is responsible for.", + "source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.", + "source_url": "https://turing.edu" +} diff --git a/exercises/practice/kindergarten-garden/.meta/src/KindergartenGarden.example.elm b/exercises/practice/kindergarten-garden/.meta/src/KindergartenGarden.example.elm new file mode 100644 index 00000000..91b924a1 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/src/KindergartenGarden.example.elm @@ -0,0 +1,101 @@ +module KindergartenGarden exposing (Plant(..), Student(..), plants) + + +type Student + = Alice + | Bob + | Charlie + | David + | Eve + | Fred + | Ginny + | Harriet + | Ileana + | Joseph + | Kincaid + | Larry + + +type Plant + = Grass + | Clover + | Radish + | Violet + + +plants : String -> Student -> List Plant +plants diagram student = + diagram + |> String.split "\n" + |> List.concatMap (takeCupsInRow student) + |> List.map decodeToPlant + + +decodeToPlant : Char -> Plant +decodeToPlant char = + case char of + 'G' -> + Grass + + 'C' -> + Clover + + 'R' -> + Radish + + 'V' -> + Violet + + _ -> + Grass + + +cupNumber : Student -> Int +cupNumber student = + case student of + Alice -> + 0 + + Bob -> + 2 + + Charlie -> + 4 + + David -> + 6 + + Eve -> + 8 + + Fred -> + 10 + + Ginny -> + 12 + + Harriet -> + 14 + + Ileana -> + 16 + + Joseph -> + 18 + + Kincaid -> + 20 + + Larry -> + 22 + + +takeCupsInRow : Student -> String -> List Char +takeCupsInRow student row = + let + number = + cupNumber student + in + row + |> String.slice number (number + 2) + |> String.toList diff --git a/exercises/practice/kindergarten-garden/.meta/tests.toml b/exercises/practice/kindergarten-garden/.meta/tests.toml new file mode 100644 index 00000000..0cdd9ad6 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/tests.toml @@ -0,0 +1,61 @@ +# 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. + +[1fc316ed-17ab-4fba-88ef-3ae78296b692] +description = "partial garden -> garden with single student" + +[acd19dc1-2200-4317-bc2a-08f021276b40] +description = "partial garden -> different garden with single student" + +[c376fcc8-349c-446c-94b0-903947315757] +description = "partial garden -> garden with two students" + +[2d620f45-9617-4924-9d27-751c80d17db9] +description = "partial garden -> multiple students for the same garden with three students -> second student's garden" + +[57712331-4896-4364-89f8-576421d69c44] +description = "partial garden -> multiple students for the same garden with three students -> third student's garden" + +[149b4290-58e1-40f2-8ae4-8b87c46e765b] +description = "full garden -> for Alice, first student's garden" + +[ba25dbbc-10bd-4a37-b18e-f89ecd098a5e] +description = "full garden -> for Bob, second student's garden" + +[566b621b-f18e-4c5f-873e-be30544b838c] +description = "full garden -> for Charlie" + +[3ad3df57-dd98-46fc-9269-1877abf612aa] +description = "full garden -> for David" + +[0f0a55d1-9710-46ed-a0eb-399ba8c72db2] +description = "full garden -> for Eve" + +[a7e80c90-b140-4ea1-aee3-f4625365c9a4] +description = "full garden -> for Fred" + +[9d94b273-2933-471b-86e8-dba68694c615] +description = "full garden -> for Ginny" + +[f55bc6c2-ade8-4844-87c4-87196f1b7258] +description = "full garden -> for Harriet" + +[759070a3-1bb1-4dd4-be2c-7cce1d7679ae] +description = "full garden -> for Ileana" + +[78578123-2755-4d4a-9c7d-e985b8dda1c6] +description = "full garden -> for Joseph" + +[6bb66df7-f433-41ab-aec2-3ead6e99f65b] +description = "full garden -> for Kincaid, second to last student's garden" + +[d7edec11-6488-418a-94e6-ed509e0fa7eb] +description = "full garden -> for Larry, last student's garden" diff --git a/exercises/practice/kindergarten-garden/elm.json b/exercises/practice/kindergarten-garden/elm.json new file mode 100644 index 00000000..22c9e137 --- /dev/null +++ b/exercises/practice/kindergarten-garden/elm.json @@ -0,0 +1,29 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/core": "1.0.5", + "elm/json": "1.1.3", + "elm/parser": "1.1.0", + "elm/random": "1.0.0", + "elm/regex": "1.0.0", + "elm/time": "1.0.0" + }, + "indirect": {} + }, + "test-dependencies": { + "direct": { + "elm-explorations/test": "2.1.0", + "rtfeldman/elm-iso8601-date-strings": "1.1.4" + }, + "indirect": { + "elm/bytes": "1.0.8", + "elm/html": "1.0.0", + "elm/virtual-dom": "1.0.3" + } + } +} diff --git a/exercises/practice/kindergarten-garden/src/KindergartenGarden.elm b/exercises/practice/kindergarten-garden/src/KindergartenGarden.elm new file mode 100644 index 00000000..230a3215 --- /dev/null +++ b/exercises/practice/kindergarten-garden/src/KindergartenGarden.elm @@ -0,0 +1,28 @@ +module KindergartenGarden exposing (Plant(..), Student(..), plants) + + +type Student + = Alice + | Bob + | Charlie + | David + | Eve + | Fred + | Ginny + | Harriet + | Ileana + | Joseph + | Kincaid + | Larry + + +type Plant + = Grass + | Clover + | Radish + | Violet + + +plants : String -> Student -> List Plant +plants diagram student = + Debug.todo "Please implement plants" diff --git a/exercises/practice/kindergarten-garden/tests/Tests.elm b/exercises/practice/kindergarten-garden/tests/Tests.elm new file mode 100644 index 00000000..0963ec5f --- /dev/null +++ b/exercises/practice/kindergarten-garden/tests/Tests.elm @@ -0,0 +1,102 @@ +module Tests exposing (tests) + +import Expect +import KindergartenGarden exposing (Plant(..), Student(..)) +import Test exposing (Test, describe, skip, test) + + +tests : Test +tests = + describe "KindergartenGarden" + [ describe "partial garden" + [ -- skip <| + test "garden with single student" <| + \() -> + KindergartenGarden.plants "RC\nGG" Alice + |> Expect.equal [ Radish, Clover, Grass, Grass ] + , skip <| + test "different garden with single student" <| + \() -> + KindergartenGarden.plants "VC\nRC" Alice + |> Expect.equal [ Violet, Clover, Radish, Clover ] + , skip <| + test "garden with two students" <| + \() -> + KindergartenGarden.plants "VVCG\nVVRC" Bob + |> Expect.equal [ Clover, Grass, Radish, Clover ] + , describe "multiple students for the same garden with three students" + [ skip <| + test "second student's garden" <| + \() -> + KindergartenGarden.plants "VVCCGG\nVVCCGG" Bob + |> Expect.equal [ Clover, Clover, Clover, Clover ] + , skip <| + test "third student's garden" <| + \() -> + KindergartenGarden.plants "VVCCGG\nVVCCGG" Charlie + |> Expect.equal [ Grass, Grass, Grass, Grass ] + ] + ] + , describe "full garden" + [ skip <| + test "for Alice, first student's garden" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Alice + |> Expect.equal [ Violet, Radish, Violet, Radish ] + , skip <| + test "for Bob, second student's garden" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Bob + |> Expect.equal [ Clover, Grass, Clover, Clover ] + , skip <| + test "for Charlie" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Charlie + |> Expect.equal [ Violet, Violet, Clover, Grass ] + , skip <| + test "for David" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" David + |> Expect.equal [ Radish, Violet, Clover, Radish ] + , skip <| + test "for Eve" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Eve + |> Expect.equal [ Clover, Grass, Radish, Grass ] + , skip <| + test "for Fred" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Fred + |> Expect.equal [ Grass, Clover, Violet, Clover ] + , skip <| + test "for Ginny" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Ginny + |> Expect.equal [ Clover, Grass, Grass, Clover ] + , skip <| + test "for Harriet" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Harriet + |> Expect.equal [ Violet, Radish, Radish, Violet ] + , skip <| + test "for Ileana" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Ileana + |> Expect.equal [ Grass, Clover, Violet, Clover ] + , skip <| + test "for Joseph" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Joseph + |> Expect.equal [ Violet, Clover, Violet, Grass ] + , skip <| + test "for Kincaid, second to last student's garden" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Kincaid + |> Expect.equal [ Grass, Clover, Clover, Grass ] + , skip <| + test "for Larry, last student's garden" <| + \() -> + KindergartenGarden.plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" Larry + |> Expect.equal [ Grass, Violet, Clover, Violet ] + ] + ]