diff --git a/config.json b/config.json index c452b416..d4e98233 100644 --- a/config.json +++ b/config.json @@ -1187,6 +1187,14 @@ "practices": [], "prerequisites": [], "difficulty": 6 + }, + { + "slug": "kindergarten-garden", + "name": "Kindergarten Garden", + "uuid": "2fd3d924-477d-4113-96a5-c9687776da49", + "practices": [], + "prerequisites": [], + "difficulty": 3 } ] }, diff --git a/exercises/practice/kindergarten-garden/.docs/instructions.md b/exercises/practice/kindergarten-garden/.docs/instructions.md new file mode 100644 index 00000000..472ee26f --- /dev/null +++ b/exercises/practice/kindergarten-garden/.docs/instructions.md @@ -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 diff --git a/exercises/practice/kindergarten-garden/.meta/config.json b/exercises/practice/kindergarten-garden/.meta/config.json new file mode 100644 index 00000000..6cdade8c --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "tomasnorre" + ], + "files": { + "solution": [ + "KindergartenGarden.php" + ], + "test": [ + "KindergartenGardenTest.php" + ], + "example": [ + ".meta/example.php" + ] + }, + "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/example.php b/exercises/practice/kindergarten-garden/.meta/example.php new file mode 100644 index 00000000..d4c2a0ba --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/example.php @@ -0,0 +1,39 @@ + 'grass', + 'C' => 'clover', + 'R' => 'radishes', + 'V' => 'violets', + ]; + + private $studentPlants = []; + + public function __construct(string $diagram) + { + $rows = explode("\n", $diagram); + foreach ($rows as $row) { + for ($i = 0, $iMax = strlen($row); $i < $iMax; $i += 2) { + $student = (int)($i / 2); + foreach (self::STUDENTS as $index => $name) { + if ($index === $student) { + $this->studentPlants[$name][] = $this->plantsMap[$row[$i]]; + $this->studentPlants[$name][] = $this->plantsMap[$row[$i + 1]]; + break; + } + } + } + } + } + + public function plants(string $student): array + { + return $this->studentPlants[$student] ?? []; + } +} 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/KindergartenGarden.php b/exercises/practice/kindergarten-garden/KindergartenGarden.php new file mode 100644 index 00000000..26932a68 --- /dev/null +++ b/exercises/practice/kindergarten-garden/KindergartenGarden.php @@ -0,0 +1,38 @@ +. + * + * To disable strict typing, comment out the directive below. + */ + +declare(strict_types=1); + +class KindergartenGarden +{ + public function __construct(string $diagram) + { + throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); + } + + public function plants(string $student): array + { + throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); + } +} diff --git a/exercises/practice/kindergarten-garden/KindergartenGardenTest.php b/exercises/practice/kindergarten-garden/KindergartenGardenTest.php new file mode 100644 index 00000000..373f94a7 --- /dev/null +++ b/exercises/practice/kindergarten-garden/KindergartenGardenTest.php @@ -0,0 +1,176 @@ +assertEquals(['radishes', 'clover', 'grass', 'grass'], $garden->plants('Alice')); + } + + /** + * uuid: acd19dc1-2200-4317-bc2a-08f021276b40 + */ + public function testDifferentGardenSingleStudent(): void + { + $garden = new KindergartenGarden("VC\nRC"); + $this->assertEquals(['violets', 'clover', 'radishes', 'clover'], $garden->plants('Alice')); + } + + /** + * uuid: c376fcc8-349c-446c-94b0-903947315757 + */ + public function testGardenWithTwoStudents(): void + { + $garden = new KindergartenGarden("VVCG\nVVRC"); + $this->assertEquals(['clover', 'grass', 'radishes', 'clover'], $garden->plants('Bob')); + } + + /** + * uuid: 2d620f45-9617-4924-9d27-751c80d17db9 + */ + public function testSecondStudentsGarden(): void + { + $garden = new KindergartenGarden("VVCCGG\nVVCCGG"); + $this->assertEquals(['clover', 'clover', 'clover', 'clover'], $garden->plants('Bob')); + } + + /** + * uuid: 57712331-4896-4364-89f8-576421d69c44 + */ + public function testThirdStudentsGarden(): void + { + $garden = new KindergartenGarden("VVCCGG\nVVCCGG"); + $this->assertEquals(['grass', 'grass', 'grass', 'grass'], $garden->plants('Charlie')); + } + + /** + * uuid: 149b4290-58e1-40f2-8ae4-8b87c46e765b + */ + public function testFullGardenForAlice(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(['violets', 'radishes', 'violets', 'radishes'], $garden->plants('Alice')); + } + + /** + * uuid: ba25dbbc-10bd-4a37-b18e-f89ecd098a5e + */ + public function testFullGardenForBob(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(['clover', 'grass', 'clover', 'clover'], $garden->plants('Bob')); + } + + /** + * uuid: 566b621b-f18e-4c5f-873e-be30544b838c + */ + public function testFullGardenForCharlie(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(['violets', 'violets', 'clover', 'grass'], $garden->plants('Charlie')); + } + + /** + * uuid: 3ad3df57-dd98-46fc-9269-1877abf612aa + */ + public function testFullGardenForDavid(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["radishes", "violets", "clover", "radishes"], $garden->plants('David')); + } + + /** + * uuid: 0f0a55d1-9710-46ed-a0eb-399ba8c72db2 + */ + public function testFullGardenForEve(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["clover", "grass", "radishes", "grass"], $garden->plants('Eve')); + } + + /** + * uuid: a7e80c90-b140-4ea1-aee3-f4625365c9a4 + */ + public function testFullGardenForFred(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["grass", "clover", "violets", "clover"], $garden->plants('Fred')); + } + + /** + * uuid: 9d94b273-2933-471b-86e8-dba68694c615 + */ + public function testFullGardenForGinny(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["clover", "grass", "grass", "clover"], $garden->plants('Ginny')); + } + + /** + * uuid: f55bc6c2-ade8-4844-87c4-87196f1b7258 + */ + public function testFullGardenForHarriet(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["violets", "radishes", "radishes", "violets"], $garden->plants('Harriet')); + } + + /** + * uuid: 759070a3-1bb1-4dd4-be2c-7cce1d7679ae + */ + public function testFullGardenForIleana(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["grass", "clover", "violets", "clover"], $garden->plants('Ileana')); + } + + /** + * uuid: 78578123-2755-4d4a-9c7d-e985b8dda1c6 + */ + public function testFullGardenForJoseph(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["violets", "clover", "violets", "grass"], $garden->plants('Joseph')); + } + + /** + * uuid: 6bb66df7-f433-41ab-aec2-3ead6e99f65b + */ + public function testFullGardenForKincaid(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["grass", "clover", "clover", "grass"], $garden->plants('Kincaid')); + } + + /** + * uuid: d7edec11-6488-418a-94e6-ed509e0fa7eb + */ + public function testFullGardenForLarry(): void + { + $diagram = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV"; + $garden = new KindergartenGarden($diagram); + $this->assertEquals(["grass", "violets", "clover", "violets"], $garden->plants('Larry')); + } +}