Skip to content

Commit c8bba21

Browse files
committed
Add kindergarten-garden
1 parent 5b24234 commit c8bba21

File tree

10 files changed

+317
-0
lines changed

10 files changed

+317
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@
242242
"pattern_matching"
243243
]
244244
},
245+
{
246+
"slug": "kindergarten-garden",
247+
"name": "Kindergarten Garden",
248+
"uuid": "a5816a38-56dc-46ed-9430-dd52690ca456",
249+
"practices": [],
250+
"prerequisites": [],
251+
"difficulty": 2
252+
},
245253
{
246254
"slug": "series",
247255
"name": "Series",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Instructions
2+
3+
Your task is to, given a diagram, determine which plants each child in the kindergarten class is responsible for.
4+
5+
There are 12 children in the class:
6+
7+
- Alice, Bob, Charlie, David, Eve, Fred, Ginny, Harriet, Ileana, Joseph, Kincaid, and Larry.
8+
9+
Four different types of seeds are planted:
10+
11+
| Plant | Diagram encoding |
12+
| ------ | ---------------- |
13+
| Grass | G |
14+
| Clover | C |
15+
| Radish | R |
16+
| Violet | V |
17+
18+
Each child gets four cups, two on each row:
19+
20+
```text
21+
[window][window][window]
22+
........................ # each dot represents a cup
23+
........................
24+
```
25+
26+
Their teacher assigns cups to the children alphabetically by their names, which means that Alice comes first and Larry comes last.
27+
28+
Here is an example diagram representing Alice's plants:
29+
30+
```text
31+
[window][window][window]
32+
VR......................
33+
RG......................
34+
```
35+
36+
In the first row, nearest the windows, she has a violet and a radish.
37+
In the second row she has a radish and some grass.
38+
39+
Your program will be given the plants from left-to-right starting with the row nearest the windows.
40+
From this, it should be able to determine which plants belong to each student.
41+
42+
For example, if it's told that the garden looks like so:
43+
44+
```text
45+
[window][window][window]
46+
VRCGVVRVCGGCCGVRGCVCGCGV
47+
VRCCCGCRRGVCGCRVVCVGCGCV
48+
```
49+
50+
Then if asked for Alice's plants, it should provide:
51+
52+
- Violets, radishes, violets, radishes
53+
54+
While asking for Bob's plants would yield:
55+
56+
- Clover, grass, clover, clover
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Introduction
2+
3+
The kindergarten class is learning about growing plants.
4+
The teacher thought it would be a good idea to give the class seeds to plant and grow in the dirt.
5+
To this end, the children have put little cups along the window sills and planted one type of plant in each cup.
6+
The children got to pick their favorites from four available types of seeds: grass, clover, radishes, and violets.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"src/kindergarten_garden.erl"
8+
],
9+
"test": [
10+
"test/kindergarten_garden_tests.erl"
11+
],
12+
"example": [
13+
".meta/example.erl"
14+
]
15+
},
16+
"blurb": "Given a diagram, determine which plants each child in the kindergarten class is responsible for.",
17+
"source": "Exercise by the JumpstartLab team for students at The Turing School of Software and Design.",
18+
"source_url": "https://turing.edu"
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-module(kindergarten_garden).
2+
3+
-export([plants/2]).
4+
5+
plants(Diagram, Student) ->
6+
[Row1, Row2] = string:split(Diagram, "\n"),
7+
Index = position_of(Student),
8+
PlantCodes = [lists:nth(Index, Row1),
9+
lists:nth(Index + 1, Row1),
10+
lists:nth(Index, Row2),
11+
lists:nth(Index + 1, Row2)],
12+
lists:map(fun code_to_plant/1, PlantCodes).
13+
14+
position_of(alice) -> 1;
15+
position_of(bob) -> 3;
16+
position_of(charlie) -> 5;
17+
position_of(david) -> 7;
18+
position_of(eve) -> 9;
19+
position_of(fred) -> 11;
20+
position_of(ginny) -> 13;
21+
position_of(harriet) -> 15;
22+
position_of(ileana) -> 17;
23+
position_of(joseph) -> 19;
24+
position_of(kincaid) -> 21;
25+
position_of(larry) -> 23.
26+
27+
code_to_plant($V) -> violets;
28+
code_to_plant($R) -> radishes;
29+
code_to_plant($C) -> clover;
30+
code_to_plant($G) -> grass.
Lines changed: 61 additions & 0 deletions
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"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
%% Erlang compiler options
2+
{erl_opts, [debug_info, warnings_as_errors]}.
3+
4+
{deps, [{erl_exercism, "0.1.2"}]}.
5+
6+
{dialyzer, [
7+
{warnings, [underspecs, no_return]},
8+
{get_warnings, true},
9+
{plt_apps, top_level_deps}, % top_level_deps | all_deps
10+
{plt_extra_apps, []},
11+
{plt_location, local}, % local | "/my/file/name"
12+
{plt_prefix, "rebar3"},
13+
{base_plt_apps, [stdlib, kernel, crypto]},
14+
{base_plt_location, global}, % global | "/my/file/name"
15+
{base_plt_prefix, "rebar3"}
16+
]}.
17+
18+
%% eunit:test(Tests)
19+
{eunit_tests, []}.
20+
%% Options for eunit:test(Tests, Opts)
21+
{eunit_opts, [verbose]}.
22+
23+
%% == xref ==
24+
25+
{xref_warnings, true}.
26+
27+
%% xref checks to run
28+
{xref_checks, [undefined_function_calls, undefined_functions,
29+
locals_not_used, exports_not_used,
30+
deprecated_function_calls, deprecated_functions]}.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{application, kindergarten_garden,
2+
[{description, "exercism.org - kindergarten-garden"},
3+
{vsn, "0.0.1"},
4+
{modules, []},
5+
{registered, []},
6+
{applications, [kernel,
7+
stdlib]},
8+
{env, []}
9+
]}.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-module(kindergarten_garden).
2+
3+
-export([plants/2]).
4+
5+
6+
plants(_Garden, _Student) -> undefined.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
-module(kindergarten_garden_tests).
2+
3+
-include_lib("erl_exercism/include/exercism.hrl").
4+
-include_lib("eunit/include/eunit.hrl").
5+
6+
7+
8+
9+
'1_garden_with_single_student_test_'() ->
10+
{"Garden with single student",
11+
?_assertEqual([radishes, clover, grass, grass],
12+
kindergarten_garden:plants("RC\nGG", alice))}.
13+
14+
'2_different_garden_with_single_student_test_'() ->
15+
{"Different garden with single student",
16+
?_assertEqual([violets, clover, radishes, clover],
17+
kindergarten_garden:plants("VC\nRC", alice))}.
18+
19+
'3_garden_with_two_students_test_'() ->
20+
{"Garden with two students",
21+
?_assertEqual([clover, grass, radishes, clover],
22+
kindergarten_garden:plants("VVCG\nVVRC", bob))}.
23+
24+
'4_Multiple_students_second_students_garden_test_'() ->
25+
{"Multiple students - second student's garden",
26+
?_assertEqual([clover, clover, clover, clover],
27+
kindergarten_garden:plants("VVCCGG\nVVCCGG", bob))}.
28+
29+
'5_Multiple_students_third_students_garden_test_'() ->
30+
{"Multiple students - third student's garden",
31+
?_assertEqual([grass, grass, grass, grass],
32+
kindergarten_garden:plants("VVCCGG\nVVCCGG", charlie))}.
33+
34+
'6_full_garden_for_alice_test_'() ->
35+
{"Full garden - for Alice",
36+
?_assertEqual([violets, radishes, violets, radishes],
37+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", alice))}.
38+
39+
'7_full_garden_for_bob_test_'() ->
40+
{"Full garden - for Bob",
41+
?_assertEqual([clover, grass, clover, clover],
42+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", bob))}.
43+
44+
'8_full_garden_for_charlie_test_'() ->
45+
{"Full garden - for Charlie",
46+
?_assertEqual([violets, violets, clover, grass],
47+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", charlie))}.
48+
49+
'9_full_garden_for_david_test_'() ->
50+
{"Full garden - for David",
51+
?_assertEqual([radishes, violets, clover, radishes],
52+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", david))}.
53+
54+
'10_full_garden_for_eve_test_'() ->
55+
{"Full garden - for Eve",
56+
?_assertEqual([clover, grass, radishes, grass],
57+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", eve))}.
58+
59+
'11_full_garden_for_fred_test_'() ->
60+
{"Full garden - for Fred",
61+
?_assertEqual([grass, clover, violets, clover],
62+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", fred))}.
63+
64+
'12_full_garden_for_ginny_test_'() ->
65+
{"Full garden - for Ginny",
66+
?_assertEqual([clover, grass, grass, clover],
67+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", ginny))}.
68+
69+
'13_full_garden_for_harriet_test_'() ->
70+
{"Full garden - for Harriet",
71+
?_assertEqual([violets, radishes, radishes, violets],
72+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", harriet))}.
73+
74+
'14_full_garden_for_ileana_test_'() ->
75+
{"Full garden - for Ileana",
76+
?_assertEqual([grass, clover, violets, clover],
77+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", ileana))}.
78+
79+
'15_full_garden_for_joseph_test_'() ->
80+
{"Full garden - for Joseph",
81+
?_assertEqual([violets, clover, violets, grass],
82+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", joseph))}.
83+
84+
'16_full_garden_for_kincaid_test_'() ->
85+
{"Full garden - for Kincaid",
86+
?_assertEqual([grass, clover, clover, grass],
87+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", kincaid))}.
88+
89+
'17_full_garden_for_larry_test_'() ->
90+
{"Full garden - for Larry",
91+
?_assertEqual([grass, violets, clover, violets],
92+
kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", larry))}.

0 commit comments

Comments
 (0)