Skip to content

Commit

Permalink
Add Kindergarten Garden exercise (#1662)
Browse files Browse the repository at this point in the history
* Add kindergarten garden exercise

* Format test file, remove first ignore

* Format example
  • Loading branch information
dem4ron authored Apr 7, 2023
1 parent c527bba commit 399488b
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,14 @@
"strings"
],
"status": "deprecated"
},
{
"slug": "kindergarten-garden",
"name": "Kindergarten Garden",
"uuid": "c27e4878-28a4-4637-bde2-2af681a7ff0d",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
],
"foregone": [
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
8 changes: 8 additions & 0 deletions exercises/practice/kindergarten-garden/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by Cargo
# Will have compiled files and executables
/target/
**/*.rs.bk

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
20 changes: 20 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"dem4ron"
],
"files": {
"solution": [
"src/lib.rs",
"Cargo.toml"
],
"test": [
"tests/kindergarten-garden.rs"
],
"example": [
".meta/example.rs"
]
},
"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"
}
35 changes: 35 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pub fn plants(diagram: &str, student: &str) -> Vec<&'static str> {
let student_names = [
"Alice", "Bob", "Charlie", "David", "Eve", "Fred", "Ginny", "Harriet", "Ileana", "Joseph",
"Kincaid", "Larry",
];
let index = student_names
.iter()
.position(|&name| name == student)
.unwrap();

let mut lines = diagram
.lines()
.map(|line| line.chars().map(plant_from_char));

let start = index * 2;
let mut first_row = lines.next().unwrap();
let mut second_row = lines.next().unwrap();

vec![
first_row.nth(start).unwrap(),
first_row.next().unwrap(),
second_row.nth(start).unwrap(),
second_row.next().unwrap(),
]
}

fn plant_from_char(c: char) -> &'static str {
match c {
'R' => "radishes",
'C' => "clover",
'G' => "grass",
'V' => "violets",
_ => "No such plant",
}
}
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"
8 changes: 8 additions & 0 deletions exercises/practice/kindergarten-garden/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "kindergarten_garden"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions exercises/practice/kindergarten-garden/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn plants(_diagram: &str, _student: &str) -> Vec<&'static str> {
unimplemented!("Solve kindergarten-garden exercise");
}
170 changes: 170 additions & 0 deletions exercises/practice/kindergarten-garden/tests/kindergarten-garden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
use kindergarten_garden::*;

#[test]
fn test_garden_with_single_student() {
let diagram = "RC
GG";
let student = "Alice";
let expected = vec!["radishes", "clover", "grass", "grass"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_different_garden_with_single_student() {
let diagram = "VC
RC";
let student = "Alice";
let expected = vec!["violets", "clover", "radishes", "clover"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_garden_with_two_students() {
let diagram = "VVCG
VVRC";
let student = "Bob";
let expected = vec!["clover", "grass", "radishes", "clover"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_second_students_garden() {
let diagram = "VVCCGG
VVCCGG";
let student = "Bob";
let expected = vec!["clover", "clover", "clover", "clover"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_third_students_garden() {
let diagram = "VVCCGG
VVCCGG";
let student = "Charlie";
let expected = vec!["grass", "grass", "grass", "grass"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_alice_first_students_garden() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Alice";
let expected = vec!["violets", "radishes", "violets", "radishes"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_bob_second_students_garden() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Bob";
let expected = vec!["clover", "grass", "clover", "clover"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_charlie() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Charlie";
let expected = vec!["violets", "violets", "clover", "grass"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_david() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "David";
let expected = vec!["radishes", "violets", "clover", "radishes"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_eve() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Eve";
let expected = vec!["clover", "grass", "radishes", "grass"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_fred() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Fred";
let expected = vec!["grass", "clover", "violets", "clover"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_ginny() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Ginny";
let expected = vec!["clover", "grass", "grass", "clover"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_harriet() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Harriet";
let expected = vec!["violets", "radishes", "radishes", "violets"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_ileana() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Ileana";
let expected = vec!["grass", "clover", "violets", "clover"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_joseph() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Joseph";
let expected = vec!["violets", "clover", "violets", "grass"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_kincaid_second_to_last_students_garden() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Kincaid";
let expected = vec!["grass", "clover", "clover", "grass"];
assert_eq!(plants(diagram, student), expected);
}

#[test]
#[ignore]
fn test_for_larry_last_students_garden() {
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV";
let student = "Larry";
let expected = vec!["grass", "violets", "clover", "violets"];
assert_eq!(plants(diagram, student), expected);
}

0 comments on commit 399488b

Please sign in to comment.