Skip to content

Commit

Permalink
Implement kindergarten-garden (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-dango authored Jul 7, 2024
1 parent f70e137 commit ffee89f
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,14 @@
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "kindergarten-garden",
"name": "Kindergarten Garden",
"uuid": "95372c5c-9b8d-4b53-b743-d99c16e7ae07",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
},
Expand Down
56 changes: 56 additions & 0 deletions exercises/practice/kindergarten-garden/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions exercises/practice/kindergarten-garden/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"m-dango"
],
"files": {
"solution": [
"lib/KindergartenGarden.rakumod"
],
"test": [
"t/kindergarten-garden.rakutest"
],
"example": [
".meta/solutions/lib/KindergartenGarden.rakumod"
]
},
"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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
unit module KindergartenGarden;

constant %PLANTS =
:C<clover>,
:G<grass>,
:R<radishes>,
:V<violets>,
;

sub plants (:$diagram, :$student) is export {
return %PLANTS{
$diagram
.lines
.map(*.substr((ord($student) - ord('A')) * 2, 2).comb.Slip)
};
}
39 changes: 39 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/template-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
properties:
plants:
test: |-
sprintf(q:to/END/, (|(%case<input><diagram student>:p), %case<expected>.List, %case<description>).map(*.raku));
cmp-ok(
plants( %s, %s ),
"~~",
%s,
%s,
);
END
unit: module
example: |-
constant %PLANTS =
:C<clover>,
:G<grass>,
:R<radishes>,
:V<violets>,
;
sub plants (:$diagram, :$student) is export {
return %PLANTS{
$diagram
.lines
.map(*.substr((ord($student) - ord('A')) * 2, 2).comb.Slip)
};
}
stub: |-
constant %PLANTS =
:C<clover>,
:G<grass>,
:R<radishes>,
:V<violets>,
;
sub plants (:$diagram, :$student) is export {
}
61 changes: 61 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
unit module KindergartenGarden;

constant %PLANTS =
:C<clover>,
:G<grass>,
:R<radishes>,
:V<violets>,
;

sub plants (:$diagram, :$student) is export {
}
125 changes: 125 additions & 0 deletions exercises/practice/kindergarten-garden/t/kindergarten-garden.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env raku
use Test;
use lib $?FILE.IO.parent(2).add('lib');
use KindergartenGarden;

cmp-ok( # begin: 1fc316ed-17ab-4fba-88ef-3ae78296b692
plants( :diagram("RC\nGG"), :student("Alice") ),
"~~",
("radishes", "clover", "grass", "grass"),
"partial garden: garden with single student",
); # end: 1fc316ed-17ab-4fba-88ef-3ae78296b692

cmp-ok( # begin: acd19dc1-2200-4317-bc2a-08f021276b40
plants( :diagram("VC\nRC"), :student("Alice") ),
"~~",
("violets", "clover", "radishes", "clover"),
"partial garden: different garden with single student",
); # end: acd19dc1-2200-4317-bc2a-08f021276b40

cmp-ok( # begin: c376fcc8-349c-446c-94b0-903947315757
plants( :diagram("VVCG\nVVRC"), :student("Bob") ),
"~~",
("clover", "grass", "radishes", "clover"),
"partial garden: garden with two students",
); # end: c376fcc8-349c-446c-94b0-903947315757

cmp-ok( # begin: 2d620f45-9617-4924-9d27-751c80d17db9
plants( :diagram("VVCCGG\nVVCCGG"), :student("Bob") ),
"~~",
("clover", "clover", "clover", "clover"),
"partial garden: multiple students for the same garden with three students: second student's garden",
); # end: 2d620f45-9617-4924-9d27-751c80d17db9

cmp-ok( # begin: 57712331-4896-4364-89f8-576421d69c44
plants( :diagram("VVCCGG\nVVCCGG"), :student("Charlie") ),
"~~",
("grass", "grass", "grass", "grass"),
"partial garden: multiple students for the same garden with three students: third student's garden",
); # end: 57712331-4896-4364-89f8-576421d69c44

cmp-ok( # begin: 149b4290-58e1-40f2-8ae4-8b87c46e765b
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Alice") ),
"~~",
("violets", "radishes", "violets", "radishes"),
"full garden: for Alice, first student's garden",
); # end: 149b4290-58e1-40f2-8ae4-8b87c46e765b

cmp-ok( # begin: ba25dbbc-10bd-4a37-b18e-f89ecd098a5e
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Bob") ),
"~~",
("clover", "grass", "clover", "clover"),
"full garden: for Bob, second student's garden",
); # end: ba25dbbc-10bd-4a37-b18e-f89ecd098a5e

cmp-ok( # begin: 566b621b-f18e-4c5f-873e-be30544b838c
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Charlie") ),
"~~",
("violets", "violets", "clover", "grass"),
"full garden: for Charlie",
); # end: 566b621b-f18e-4c5f-873e-be30544b838c

cmp-ok( # begin: 3ad3df57-dd98-46fc-9269-1877abf612aa
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("David") ),
"~~",
("radishes", "violets", "clover", "radishes"),
"full garden: for David",
); # end: 3ad3df57-dd98-46fc-9269-1877abf612aa

cmp-ok( # begin: 0f0a55d1-9710-46ed-a0eb-399ba8c72db2
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Eve") ),
"~~",
("clover", "grass", "radishes", "grass"),
"full garden: for Eve",
); # end: 0f0a55d1-9710-46ed-a0eb-399ba8c72db2

cmp-ok( # begin: a7e80c90-b140-4ea1-aee3-f4625365c9a4
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Fred") ),
"~~",
("grass", "clover", "violets", "clover"),
"full garden: for Fred",
); # end: a7e80c90-b140-4ea1-aee3-f4625365c9a4

cmp-ok( # begin: 9d94b273-2933-471b-86e8-dba68694c615
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Ginny") ),
"~~",
("clover", "grass", "grass", "clover"),
"full garden: for Ginny",
); # end: 9d94b273-2933-471b-86e8-dba68694c615

cmp-ok( # begin: f55bc6c2-ade8-4844-87c4-87196f1b7258
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Harriet") ),
"~~",
("violets", "radishes", "radishes", "violets"),
"full garden: for Harriet",
); # end: f55bc6c2-ade8-4844-87c4-87196f1b7258

cmp-ok( # begin: 759070a3-1bb1-4dd4-be2c-7cce1d7679ae
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Ileana") ),
"~~",
("grass", "clover", "violets", "clover"),
"full garden: for Ileana",
); # end: 759070a3-1bb1-4dd4-be2c-7cce1d7679ae

cmp-ok( # begin: 78578123-2755-4d4a-9c7d-e985b8dda1c6
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Joseph") ),
"~~",
("violets", "clover", "violets", "grass"),
"full garden: for Joseph",
); # end: 78578123-2755-4d4a-9c7d-e985b8dda1c6

cmp-ok( # begin: 6bb66df7-f433-41ab-aec2-3ead6e99f65b
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Kincaid") ),
"~~",
("grass", "clover", "clover", "grass"),
"full garden: for Kincaid, second to last student's garden",
); # end: 6bb66df7-f433-41ab-aec2-3ead6e99f65b

cmp-ok( # begin: d7edec11-6488-418a-94e6-ed509e0fa7eb
plants( :diagram("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"), :student("Larry") ),
"~~",
("grass", "violets", "clover", "violets"),
"full garden: for Larry, last student's garden",
); # end: d7edec11-6488-418a-94e6-ed509e0fa7eb

done-testing;

0 comments on commit ffee89f

Please sign in to comment.