Skip to content

Commit

Permalink
feat: Add kindergarten-garden (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiravillekode authored Nov 16, 2023
1 parent 2ad663a commit 1656fde
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "kindergarten-garden",
"name": "Kindergarten Garden",
"uuid": "fb94d392-5356-4c21-9de9-618f473a780d",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "luhn",
"name": "Luhn",
Expand Down
58 changes: 58 additions & 0 deletions exercises/practice/kindergarten-garden/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Instructions

Given a diagram, determine which plants each child in the kindergarten class is
responsible for.

The kindergarten class is learning about growing plants.
The teacher thought it would be a good idea to give them actual seeds, plant them in actual dirt, and grow actual plants.

They've chosen to grow grass, clover, radishes, and violets.

To this end, the children have put little cups along the window sills, and
planted one type of plant in each cup, choosing randomly from the available
types of seeds.

```text
[window][window][window]
........................ # each dot represents a cup
........................
```

There are 12 children in the class:

- Alice, Bob, Charlie, David,
- Eve, Fred, Ginny, Harriet,
- Ileana, Joseph, Kincaid, and Larry.

Each child gets 4 cups, two on each row.
Their teacher assigns cups to the children alphabetically by their names.

The following diagram represents 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
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": [
"keiravillekode"
],
"files": {
"solution": [
"kindergarten-garden.v"
],
"test": [
"run_test.v"
],
"example": [
".meta/example.v"
]
},
"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"
}
32 changes: 32 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/example.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module main

fn plant(letter rune) string {
if letter == `G` {
return "grass"
}
if letter == `C` {
return "clover"
}
if letter == `R` {
return "radishes"
}
if letter == `V` {
return "violets"
}

return ""
}

fn plants(diagram string, student string) []string {
first := 2 * (student[0] - `A`)
second := first + 1
third := (diagram.len + 1) / 2 + first
fourth := third + 1

return [
plant(diagram[first]),
plant(diagram[second]),
plant(diagram[third]),
plant(diagram[fourth])
]
}
54 changes: 54 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in 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"
4 changes: 4 additions & 0 deletions exercises/practice/kindergarten-garden/kindergarten-garden.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module main

fn plants(diagram string, student string) []string {
}
103 changes: 103 additions & 0 deletions exercises/practice/kindergarten-garden/run_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module main

fn test_partial_garden__garden_with_single_student() {
diagram := 'RC\nGG'
expect := ['radishes', 'clover', 'grass', 'grass']
assert plants(diagram, 'Alice') == expect
}

fn test_partial_garden__different_garden_with_single_student() {
diagram := 'VC\nRC'
expect := ['violets', 'clover', 'radishes', 'clover']
assert plants(diagram, 'Alice') == expect
}

fn test_partial_garden__garden_with_two_students() {
diagram := 'VVCG\nVVRC'
expect := ['clover', 'grass', 'radishes', 'clover']
assert plants(diagram, 'Bob') == expect
}

fn test_partial_garden__multiple_students_for_the_same_garden_with_three_students__second_students_garden() {
diagram := 'VVCCGG\nVVCCGG'
expect := ['clover', 'clover', 'clover', 'clover']
assert plants(diagram, 'Bob') == expect
}

fn test_partial_garden__multiple_students_for_the_same_garden_with_three_students__third_students_garden() {
diagram := 'VVCCGG\nVVCCGG'
expect := ['grass', 'grass', 'grass', 'grass']
assert plants(diagram, 'Charlie') == expect
}

fn test_full_garden__for_alice_first_students_garden() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['violets', 'radishes', 'violets', 'radishes']
assert plants(diagram, 'Alice') == expect
}

fn test_full_garden__for_bob_second_students_garden() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['clover', 'grass', 'clover', 'clover']
assert plants(diagram, 'Bob') == expect
}

fn test_full_garden__for_charlie() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['violets', 'violets', 'clover', 'grass']
assert plants(diagram, 'Charlie') == expect
}

fn test_full_garden__for_david() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['radishes', 'violets', 'clover', 'radishes']
assert plants(diagram, 'David') == expect
}

fn test_full_garden__for_eve() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['clover', 'grass', 'radishes', 'grass']
assert plants(diagram, 'Eve') == expect
}

fn test_full_garden__for_fred() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['grass', 'clover', 'violets', 'clover']
assert plants(diagram, 'Fred') == expect
}

fn test_full_garden__for_ginny() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['clover', 'grass', 'grass', 'clover']
assert plants(diagram, 'Ginny') == expect
}

fn test_full_garden__for_harriet() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['violets', 'radishes', 'radishes', 'violets']
assert plants(diagram, 'Harriet') == expect
}

fn test_full_garden__for_ileana() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['grass', 'clover', 'violets', 'clover']
assert plants(diagram, 'Ileana') == expect
}

fn test_full_garden__for_joseph() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['violets', 'clover', 'violets', 'grass']
assert plants(diagram, 'Joseph') == expect
}

fn test_full_garden__for_kincaid_second_to_last_students_garden() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['grass', 'clover', 'clover', 'grass']
assert plants(diagram, 'Kincaid') == expect
}

fn test_full_garden__for_larry_last_students_garden() {
diagram := 'VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV'
expect := ['grass', 'violets', 'clover', 'violets']
assert plants(diagram, 'Larry') == expect
}

0 comments on commit 1656fde

Please sign in to comment.