Skip to content

Commit a74cc45

Browse files
authored
Merge pull request #137 from exercism/kindergarten-garden-exercise
kindergarten-garden-exercise: Added new exercise.
2 parents f39ab0e + 6c834a0 commit a74cc45

10 files changed

+406
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,14 @@
455455
"prerequisites": [],
456456
"difficulty": 2
457457
},
458+
{
459+
"slug": "kindergarten-garden",
460+
"name": "Kindergarten Garden",
461+
"uuid": "2623646b-91a2-485e-a9e5-e4b5f9194f28",
462+
"practices": [],
463+
"prerequisites": [],
464+
"difficulty": 3
465+
},
458466
{
459467
"slug": "anagram",
460468
"name": "Anagram",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Instructions
2+
3+
Your task is to, given a diagram, determine which plants each child in the kindergarten class is responsible for.
4+
5+
There are 12 children in the class:
6+
7+
- Alice, Bob, Charlie, David, Eve, Fred, Ginny, Harriet, Ileana, Joseph, Kincaid, and Larry.
8+
9+
Four different types of seeds are planted:
10+
11+
| Plant | Diagram encoding |
12+
| ------ | ---------------- |
13+
| Grass | G |
14+
| Clover | C |
15+
| Radish | R |
16+
| Violet | V |
17+
18+
Each child gets four cups, two on each row:
19+
20+
```text
21+
[window][window][window]
22+
........................ # each dot represents a cup
23+
........................
24+
```
25+
26+
Their teacher assigns cups to the children alphabetically by their names, which means that Alice comes first and Larry comes last.
27+
28+
Here is an example diagram representing Alice's plants:
29+
30+
```text
31+
[window][window][window]
32+
VR......................
33+
RG......................
34+
```
35+
36+
In the first row, nearest the windows, she has a violet and a radish.
37+
In the second row she has a radish and some grass.
38+
39+
Your program will be given the plants from left-to-right starting with the row nearest the windows.
40+
From this, it should be able to determine which plants belong to each student.
41+
42+
For example, if it's told that the garden looks like so:
43+
44+
```text
45+
[window][window][window]
46+
VRCGVVRVCGGCCGVRGCVCGCGV
47+
VRCCCGCRRGVCGCRVVCVGCGCV
48+
```
49+
50+
Then if asked for Alice's plants, it should provide:
51+
52+
- Violets, radishes, violets, radishes
53+
54+
While asking for Bob's plants would yield:
55+
56+
- Clover, grass, clover, clover
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Introduction
2+
3+
The kindergarten class is learning about growing plants.
4+
The teacher thought it would be a good idea to give the class seeds to plant and grow in the dirt.
5+
To this end, the children have put little cups along the window sills and planted one type of plant in each cup.
6+
The children got to pick their favorites from four available types of seeds: grass, clover, radishes, and violets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"SimaDovakin"
4+
],
5+
"files": {
6+
"solution": [
7+
"kindergartenGarden.u"
8+
],
9+
"test": [
10+
"kindergartenGarden.test.u"
11+
],
12+
"example": [
13+
".meta/examples/kindergartenGarden.example.u"
14+
]
15+
},
16+
"blurb": "Given a diagram, determine which plants each child in the kindergarten class is responsible for.",
17+
"source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
18+
"source_url": "https://turing.edu"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
unique type kindergartenGarden.Plant
2+
= Clover
3+
| Grass
4+
| Radishes
5+
| Violets
6+
7+
unique type kindergartenGarden.Garden
8+
= Garden (Map Text [kindergartenGarden.Plant])
9+
10+
{{
11+
Accepts a list of students' names and raw garden diagram and returns Garden type.
12+
}}
13+
kindergartenGarden.garden : [Text] -> Text -> Garden
14+
kindergartenGarden.garden students plants =
15+
rows = lines plants
16+
(firstRow, lastRow) = (head rows, last rows)
17+
processedPlants =
18+
processRows (getOrElse "" firstRow) (getOrElse "" lastRow)
19+
Garden (zip students processedPlants |> fromList)
20+
21+
{{
22+
Accepts student's name and Garden and returns list of plants.
23+
}}
24+
kindergartenGarden.lookupPlants : Text -> Garden -> [Plant]
25+
kindergartenGarden.lookupPlants student garden =
26+
(Garden cups) = garden
27+
cups
28+
|> Map.get student
29+
|> Optional.getOrElse []
30+
31+
kindergartenGarden.toPlant : Char -> Plant
32+
kindergartenGarden.toPlant = cases
33+
?C -> Clover
34+
?G -> Grass
35+
?R -> Radishes
36+
?V -> Violets
37+
_ -> Grass
38+
39+
kindergartenGarden.processRows : Text -> Text -> [[Plant]]
40+
kindergartenGarden.processRows = cases
41+
"", "" -> []
42+
row1, row2 -> match (toCharList row1, toCharList row2) with
43+
([x, y] ++ xs, [n, m] ++ ns) ->
44+
(map toPlant [x, y, n, m]) +: processRows (fromCharList xs) (fromCharList ns)
45+
_ -> []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[
2+
{
3+
"name": "kindergartenGarden.lookupPlants.tests.ex1",
4+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"RC\\nGG\"\n expect ([Radishes, Clover, Grass, Grass] === kindergartenGarden.lookupPlants \"Alice\" garden)\n |> Test.label \"partial garden - garden with single student\""
5+
},
6+
{
7+
"name": "kindergartenGarden.lookupPlants.tests.ex2",
8+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VC\\nRC\"\n expect ([Violets, Clover, Radishes, Clover] === kindergartenGarden.lookupPlants \"Alice\" garden)\n |> Test.label \"partial garden - different garden with single student\""
9+
},
10+
{
11+
"name": "kindergartenGarden.lookupPlants.tests.ex3",
12+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VVCG\\nVVRC\"\n expect ([Clover, Grass, Radishes, Clover] === kindergartenGarden.lookupPlants \"Bob\" garden)\n |> Test.label \"partial garden - garden with two students\""
13+
},
14+
{
15+
"name": "kindergartenGarden.lookupPlants.tests.ex4",
16+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VVCCGG\\nVVCCGG\"\n expect ([Clover, Clover, Clover, Clover] === kindergartenGarden.lookupPlants \"Bob\" garden)\n |> Test.label \"partial garden - multiple students for the same garden with three students - second student's garden\""
17+
},
18+
{
19+
"name": "kindergartenGarden.lookupPlants.tests.ex5",
20+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VVCCGG\\nVVCCGG\"\n expect ([Grass, Grass, Grass, Grass] === kindergartenGarden.lookupPlants \"Charlie\" garden)\n |> Test.label \"partial garden - multiple students for the same garden with three students - third student's garden\""
21+
},
22+
{
23+
"name": "kindergartenGarden.lookupPlants.tests.ex6",
24+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Violets, Radishes, Violets, Radishes] === kindergartenGarden.lookupPlants \"Alice\" garden)\n |> Test.label \"full garden - for Alice, first student's garden\""
25+
},
26+
{
27+
"name": "kindergartenGarden.lookupPlants.tests.ex7",
28+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Clover, Grass, Clover, Clover] === kindergartenGarden.lookupPlants \"Bob\" garden)\n |> Test.label \"full garden - for Bob, second student's garden\""
29+
},
30+
{
31+
"name": "kindergartenGarden.lookupPlants.tests.ex8",
32+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Violets, Violets, Clover, Grass] === kindergartenGarden.lookupPlants \"Charlie\" garden)\n |> Test.label \"full garden - for Charlie\""
33+
},
34+
{
35+
"name": "kindergartenGarden.lookupPlants.tests.ex9",
36+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Radishes, Violets, Clover, Radishes] === kindergartenGarden.lookupPlants \"David\" garden)\n |> Test.label \"full garden - for David\""
37+
},
38+
{
39+
"name": "kindergartenGarden.lookupPlants.tests.ex10",
40+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Clover, Grass, Radishes, Grass] === kindergartenGarden.lookupPlants \"Eve\" garden)\n |> Test.label \"full garden - for Eve\""
41+
},
42+
{
43+
"name": "kindergartenGarden.lookupPlants.tests.ex11",
44+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Grass, Clover, Violets, Clover] === kindergartenGarden.lookupPlants \"Fred\" garden)\n |> Test.label \"full garden - for Fred\""
45+
},
46+
{
47+
"name": "kindergartenGarden.lookupPlants.tests.ex12",
48+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Clover, Grass, Grass, Clover] === kindergartenGarden.lookupPlants \"Ginny\" garden)\n |> Test.label \"full garden - for Ginny\""
49+
},
50+
{
51+
"name": "kindergartenGarden.lookupPlants.tests.ex13",
52+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Violets, Radishes, Radishes, Violets] === kindergartenGarden.lookupPlants \"Harriet\" garden)\n |> Test.label \"full garden - for Harriet\""
53+
},
54+
{
55+
"name": "kindergartenGarden.lookupPlants.tests.ex14",
56+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Grass, Clover, Violets, Clover] === kindergartenGarden.lookupPlants \"Ileana\" garden)\n |> Test.label \"full garden - for Ileana\""
57+
},
58+
{
59+
"name": "kindergartenGarden.lookupPlants.tests.ex15",
60+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Violets, Clover, Violets, Grass] === kindergartenGarden.lookupPlants \"Joseph\" garden)\n |> Test.label \"full garden - for Joseph\""
61+
},
62+
{
63+
"name": "kindergartenGarden.lookupPlants.tests.ex16",
64+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Grass, Clover, Clover, Grass] === kindergartenGarden.lookupPlants \"Kincaid\" garden)\n |> Test.label \"full garden - for Kincaid, second to last student's garden\""
65+
},
66+
{
67+
"name": "kindergartenGarden.lookupPlants.tests.ex17",
68+
"test_code": "garden = kindergartenGarden.tests.defaultGarden \"VRCGVVRVCGGCCGVRGCVCGCGV\\nVRCCCGCRRGVCGCRVVCVGCGCV\"\n expect ([Grass, Violets, Clover, Violets] === kindergartenGarden.lookupPlants \"Larry\" garden)\n |> Test.label \"full garden - for Larry, last student's garden\""
69+
}
70+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Testing transcript for kindergarten-garden exercise
2+
3+
```ucm
4+
.> load ./kindergartenGarden.u
5+
.> add
6+
.> load ./kindergartenGarden.test.u
7+
.> add
8+
.> move.term kindergartenGarden.tests tests
9+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
[1fc316ed-17ab-4fba-88ef-3ae78296b692]
13+
description = "partial garden -> garden with single student"
14+
15+
[acd19dc1-2200-4317-bc2a-08f021276b40]
16+
description = "partial garden -> different garden with single student"
17+
18+
[c376fcc8-349c-446c-94b0-903947315757]
19+
description = "partial garden -> garden with two students"
20+
21+
[2d620f45-9617-4924-9d27-751c80d17db9]
22+
description = "partial garden -> multiple students for the same garden with three students -> second student's garden"
23+
24+
[57712331-4896-4364-89f8-576421d69c44]
25+
description = "partial garden -> multiple students for the same garden with three students -> third student's garden"
26+
27+
[149b4290-58e1-40f2-8ae4-8b87c46e765b]
28+
description = "full garden -> for Alice, first student's garden"
29+
30+
[ba25dbbc-10bd-4a37-b18e-f89ecd098a5e]
31+
description = "full garden -> for Bob, second student's garden"
32+
33+
[566b621b-f18e-4c5f-873e-be30544b838c]
34+
description = "full garden -> for Charlie"
35+
36+
[3ad3df57-dd98-46fc-9269-1877abf612aa]
37+
description = "full garden -> for David"
38+
39+
[0f0a55d1-9710-46ed-a0eb-399ba8c72db2]
40+
description = "full garden -> for Eve"
41+
42+
[a7e80c90-b140-4ea1-aee3-f4625365c9a4]
43+
description = "full garden -> for Fred"
44+
45+
[9d94b273-2933-471b-86e8-dba68694c615]
46+
description = "full garden -> for Ginny"
47+
48+
[f55bc6c2-ade8-4844-87c4-87196f1b7258]
49+
description = "full garden -> for Harriet"
50+
51+
[759070a3-1bb1-4dd4-be2c-7cce1d7679ae]
52+
description = "full garden -> for Ileana"
53+
54+
[78578123-2755-4d4a-9c7d-e985b8dda1c6]
55+
description = "full garden -> for Joseph"
56+
57+
[6bb66df7-f433-41ab-aec2-3ead6e99f65b]
58+
description = "full garden -> for Kincaid, second to last student's garden"
59+
60+
[d7edec11-6488-418a-94e6-ed509e0fa7eb]
61+
description = "full garden -> for Larry, last student's garden"

0 commit comments

Comments
 (0)