Skip to content

Commit 399488b

Browse files
authored
Add Kindergarten Garden exercise (#1662)
* Add kindergarten garden exercise * Format test file, remove first ignore * Format example
1 parent c527bba commit 399488b

File tree

9 files changed

+371
-0
lines changed

9 files changed

+371
-0
lines changed

config.json

+8
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,14 @@
15071507
"strings"
15081508
],
15091509
"status": "deprecated"
1510+
},
1511+
{
1512+
"slug": "kindergarten-garden",
1513+
"name": "Kindergarten Garden",
1514+
"uuid": "c27e4878-28a4-4637-bde2-2af681a7ff0d",
1515+
"practices": [],
1516+
"prerequisites": [],
1517+
"difficulty": 1
15101518
}
15111519
],
15121520
"foregone": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Instructions
2+
3+
Given a diagram, determine which plants each child in the kindergarten class is
4+
responsible for.
5+
6+
The kindergarten class is learning about growing plants.
7+
The teacher thought it would be a good idea to give them actual seeds, plant them in actual dirt, and grow actual plants.
8+
9+
They've chosen to grow grass, clover, radishes, and violets.
10+
11+
To this end, the children have put little cups along the window sills, and
12+
planted one type of plant in each cup, choosing randomly from the available
13+
types of seeds.
14+
15+
```text
16+
[window][window][window]
17+
........................ # each dot represents a cup
18+
........................
19+
```
20+
21+
There are 12 children in the class:
22+
23+
- Alice, Bob, Charlie, David,
24+
- Eve, Fred, Ginny, Harriet,
25+
- Ileana, Joseph, Kincaid, and Larry.
26+
27+
Each child gets 4 cups, two on each row.
28+
Their teacher assigns cups to the children alphabetically by their names.
29+
30+
The following diagram represents Alice's plants:
31+
32+
```text
33+
[window][window][window]
34+
VR......................
35+
RG......................
36+
```
37+
38+
In the first row, nearest the windows, she has a violet and a radish.
39+
In the second row she has a radish and some grass.
40+
41+
Your program will be given the plants from left-to-right starting with the row nearest the windows.
42+
From this, it should be able to determine which plants belong to each student.
43+
44+
For example, if it's told that the garden looks like so:
45+
46+
```text
47+
[window][window][window]
48+
VRCGVVRVCGGCCGVRGCVCGCGV
49+
VRCCCGCRRGVCGCRVVCVGCGCV
50+
```
51+
52+
Then if asked for Alice's plants, it should provide:
53+
54+
- Violets, radishes, violets, radishes
55+
56+
While asking for Bob's plants would yield:
57+
58+
- Clover, grass, clover, clover
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Generated by Cargo
2+
# Will have compiled files and executables
3+
/target/
4+
**/*.rs.bk
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
8+
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"authors": [
3+
"dem4ron"
4+
],
5+
"files": {
6+
"solution": [
7+
"src/lib.rs",
8+
"Cargo.toml"
9+
],
10+
"test": [
11+
"tests/kindergarten-garden.rs"
12+
],
13+
"example": [
14+
".meta/example.rs"
15+
]
16+
},
17+
"blurb": "Given a diagram, determine which plants each child in the kindergarten class is responsible for.",
18+
"source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
19+
"source_url": "https://turing.edu"
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
pub fn plants(diagram: &str, student: &str) -> Vec<&'static str> {
2+
let student_names = [
3+
"Alice", "Bob", "Charlie", "David", "Eve", "Fred", "Ginny", "Harriet", "Ileana", "Joseph",
4+
"Kincaid", "Larry",
5+
];
6+
let index = student_names
7+
.iter()
8+
.position(|&name| name == student)
9+
.unwrap();
10+
11+
let mut lines = diagram
12+
.lines()
13+
.map(|line| line.chars().map(plant_from_char));
14+
15+
let start = index * 2;
16+
let mut first_row = lines.next().unwrap();
17+
let mut second_row = lines.next().unwrap();
18+
19+
vec![
20+
first_row.nth(start).unwrap(),
21+
first_row.next().unwrap(),
22+
second_row.nth(start).unwrap(),
23+
second_row.next().unwrap(),
24+
]
25+
}
26+
27+
fn plant_from_char(c: char) -> &'static str {
28+
match c {
29+
'R' => "radishes",
30+
'C' => "clover",
31+
'G' => "grass",
32+
'V' => "violets",
33+
_ => "No such plant",
34+
}
35+
}
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"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "kindergarten_garden"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn plants(_diagram: &str, _student: &str) -> Vec<&'static str> {
2+
unimplemented!("Solve kindergarten-garden exercise");
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
use kindergarten_garden::*;
2+
3+
#[test]
4+
fn test_garden_with_single_student() {
5+
let diagram = "RC
6+
GG";
7+
let student = "Alice";
8+
let expected = vec!["radishes", "clover", "grass", "grass"];
9+
assert_eq!(plants(diagram, student), expected);
10+
}
11+
12+
#[test]
13+
#[ignore]
14+
fn test_different_garden_with_single_student() {
15+
let diagram = "VC
16+
RC";
17+
let student = "Alice";
18+
let expected = vec!["violets", "clover", "radishes", "clover"];
19+
assert_eq!(plants(diagram, student), expected);
20+
}
21+
22+
#[test]
23+
#[ignore]
24+
fn test_garden_with_two_students() {
25+
let diagram = "VVCG
26+
VVRC";
27+
let student = "Bob";
28+
let expected = vec!["clover", "grass", "radishes", "clover"];
29+
assert_eq!(plants(diagram, student), expected);
30+
}
31+
32+
#[test]
33+
#[ignore]
34+
fn test_second_students_garden() {
35+
let diagram = "VVCCGG
36+
VVCCGG";
37+
let student = "Bob";
38+
let expected = vec!["clover", "clover", "clover", "clover"];
39+
assert_eq!(plants(diagram, student), expected);
40+
}
41+
42+
#[test]
43+
#[ignore]
44+
fn test_third_students_garden() {
45+
let diagram = "VVCCGG
46+
VVCCGG";
47+
let student = "Charlie";
48+
let expected = vec!["grass", "grass", "grass", "grass"];
49+
assert_eq!(plants(diagram, student), expected);
50+
}
51+
52+
#[test]
53+
#[ignore]
54+
fn test_for_alice_first_students_garden() {
55+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
56+
VRCCCGCRRGVCGCRVVCVGCGCV";
57+
let student = "Alice";
58+
let expected = vec!["violets", "radishes", "violets", "radishes"];
59+
assert_eq!(plants(diagram, student), expected);
60+
}
61+
62+
#[test]
63+
#[ignore]
64+
fn test_for_bob_second_students_garden() {
65+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
66+
VRCCCGCRRGVCGCRVVCVGCGCV";
67+
let student = "Bob";
68+
let expected = vec!["clover", "grass", "clover", "clover"];
69+
assert_eq!(plants(diagram, student), expected);
70+
}
71+
72+
#[test]
73+
#[ignore]
74+
fn test_for_charlie() {
75+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
76+
VRCCCGCRRGVCGCRVVCVGCGCV";
77+
let student = "Charlie";
78+
let expected = vec!["violets", "violets", "clover", "grass"];
79+
assert_eq!(plants(diagram, student), expected);
80+
}
81+
82+
#[test]
83+
#[ignore]
84+
fn test_for_david() {
85+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
86+
VRCCCGCRRGVCGCRVVCVGCGCV";
87+
let student = "David";
88+
let expected = vec!["radishes", "violets", "clover", "radishes"];
89+
assert_eq!(plants(diagram, student), expected);
90+
}
91+
92+
#[test]
93+
#[ignore]
94+
fn test_for_eve() {
95+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
96+
VRCCCGCRRGVCGCRVVCVGCGCV";
97+
let student = "Eve";
98+
let expected = vec!["clover", "grass", "radishes", "grass"];
99+
assert_eq!(plants(diagram, student), expected);
100+
}
101+
102+
#[test]
103+
#[ignore]
104+
fn test_for_fred() {
105+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
106+
VRCCCGCRRGVCGCRVVCVGCGCV";
107+
let student = "Fred";
108+
let expected = vec!["grass", "clover", "violets", "clover"];
109+
assert_eq!(plants(diagram, student), expected);
110+
}
111+
112+
#[test]
113+
#[ignore]
114+
fn test_for_ginny() {
115+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
116+
VRCCCGCRRGVCGCRVVCVGCGCV";
117+
let student = "Ginny";
118+
let expected = vec!["clover", "grass", "grass", "clover"];
119+
assert_eq!(plants(diagram, student), expected);
120+
}
121+
122+
#[test]
123+
#[ignore]
124+
fn test_for_harriet() {
125+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
126+
VRCCCGCRRGVCGCRVVCVGCGCV";
127+
let student = "Harriet";
128+
let expected = vec!["violets", "radishes", "radishes", "violets"];
129+
assert_eq!(plants(diagram, student), expected);
130+
}
131+
132+
#[test]
133+
#[ignore]
134+
fn test_for_ileana() {
135+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
136+
VRCCCGCRRGVCGCRVVCVGCGCV";
137+
let student = "Ileana";
138+
let expected = vec!["grass", "clover", "violets", "clover"];
139+
assert_eq!(plants(diagram, student), expected);
140+
}
141+
142+
#[test]
143+
#[ignore]
144+
fn test_for_joseph() {
145+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
146+
VRCCCGCRRGVCGCRVVCVGCGCV";
147+
let student = "Joseph";
148+
let expected = vec!["violets", "clover", "violets", "grass"];
149+
assert_eq!(plants(diagram, student), expected);
150+
}
151+
152+
#[test]
153+
#[ignore]
154+
fn test_for_kincaid_second_to_last_students_garden() {
155+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
156+
VRCCCGCRRGVCGCRVVCVGCGCV";
157+
let student = "Kincaid";
158+
let expected = vec!["grass", "clover", "clover", "grass"];
159+
assert_eq!(plants(diagram, student), expected);
160+
}
161+
162+
#[test]
163+
#[ignore]
164+
fn test_for_larry_last_students_garden() {
165+
let diagram = "VRCGVVRVCGGCCGVRGCVCGCGV
166+
VRCCCGCRRGVCGCRVVCVGCGCV";
167+
let student = "Larry";
168+
let expected = vec!["grass", "violets", "clover", "violets"];
169+
assert_eq!(plants(diagram, student), expected);
170+
}

0 commit comments

Comments
 (0)