From c8bba212626e0973b6b4ca181e1400fc72980373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sat, 5 Apr 2025 21:09:01 -0700 Subject: [PATCH 1/2] Add `kindergarten-garden` --- config.json | 8 ++ .../kindergarten-garden/.docs/instructions.md | 56 +++++++++++ .../kindergarten-garden/.docs/introduction.md | 6 ++ .../kindergarten-garden/.meta/config.json | 19 ++++ .../kindergarten-garden/.meta/example.erl | 30 ++++++ .../kindergarten-garden/.meta/tests.toml | 61 ++++++++++++ .../practice/kindergarten-garden/rebar.config | 30 ++++++ .../src/kindergarten_garden.app.src | 9 ++ .../src/kindergarten_garden.erl | 6 ++ .../test/kindergarten_garden_tests.erl | 92 +++++++++++++++++++ 10 files changed, 317 insertions(+) create mode 100644 exercises/practice/kindergarten-garden/.docs/instructions.md create mode 100644 exercises/practice/kindergarten-garden/.docs/introduction.md create mode 100644 exercises/practice/kindergarten-garden/.meta/config.json create mode 100644 exercises/practice/kindergarten-garden/.meta/example.erl create mode 100644 exercises/practice/kindergarten-garden/.meta/tests.toml create mode 100644 exercises/practice/kindergarten-garden/rebar.config create mode 100644 exercises/practice/kindergarten-garden/src/kindergarten_garden.app.src create mode 100644 exercises/practice/kindergarten-garden/src/kindergarten_garden.erl create mode 100644 exercises/practice/kindergarten-garden/test/kindergarten_garden_tests.erl diff --git a/config.json b/config.json index 3175db29..6aa57bd2 100644 --- a/config.json +++ b/config.json @@ -242,6 +242,14 @@ "pattern_matching" ] }, + { + "slug": "kindergarten-garden", + "name": "Kindergarten Garden", + "uuid": "a5816a38-56dc-46ed-9430-dd52690ca456", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "series", "name": "Series", diff --git a/exercises/practice/kindergarten-garden/.docs/instructions.md b/exercises/practice/kindergarten-garden/.docs/instructions.md new file mode 100644 index 00000000..6fe11a58 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.docs/instructions.md @@ -0,0 +1,56 @@ +# Instructions + +Your task is to, given a diagram, determine which plants each child in the kindergarten class is responsible for. + +There are 12 children in the class: + +- Alice, Bob, Charlie, David, Eve, Fred, Ginny, Harriet, Ileana, Joseph, Kincaid, and Larry. + +Four different types of seeds are planted: + +| Plant | Diagram encoding | +| ------ | ---------------- | +| Grass | G | +| Clover | C | +| Radish | R | +| Violet | V | + +Each child gets four cups, two on each row: + +```text +[window][window][window] +........................ # each dot represents a cup +........................ +``` + +Their teacher assigns cups to the children alphabetically by their names, which means that Alice comes first and Larry comes last. + +Here is an example diagram representing 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/.docs/introduction.md b/exercises/practice/kindergarten-garden/.docs/introduction.md new file mode 100644 index 00000000..5ad97d23 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.docs/introduction.md @@ -0,0 +1,6 @@ +# Introduction + +The kindergarten class is learning about growing plants. +The teacher thought it would be a good idea to give the class seeds to plant and grow in the dirt. +To this end, the children have put little cups along the window sills and planted one type of plant in each cup. +The children got to pick their favorites from four available types of seeds: grass, clover, radishes, and violets. diff --git a/exercises/practice/kindergarten-garden/.meta/config.json b/exercises/practice/kindergarten-garden/.meta/config.json new file mode 100644 index 00000000..78339d46 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "src/kindergarten_garden.erl" + ], + "test": [ + "test/kindergarten_garden_tests.erl" + ], + "example": [ + ".meta/example.erl" + ] + }, + "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.erl b/exercises/practice/kindergarten-garden/.meta/example.erl new file mode 100644 index 00000000..3a5ed2e1 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/example.erl @@ -0,0 +1,30 @@ +-module(kindergarten_garden). + +-export([plants/2]). + +plants(Diagram, Student) -> + [Row1, Row2] = string:split(Diagram, "\n"), + Index = position_of(Student), + PlantCodes = [lists:nth(Index, Row1), + lists:nth(Index + 1, Row1), + lists:nth(Index, Row2), + lists:nth(Index + 1, Row2)], + lists:map(fun code_to_plant/1, PlantCodes). + +position_of(alice) -> 1; +position_of(bob) -> 3; +position_of(charlie) -> 5; +position_of(david) -> 7; +position_of(eve) -> 9; +position_of(fred) -> 11; +position_of(ginny) -> 13; +position_of(harriet) -> 15; +position_of(ileana) -> 17; +position_of(joseph) -> 19; +position_of(kincaid) -> 21; +position_of(larry) -> 23. + +code_to_plant($V) -> violets; +code_to_plant($R) -> radishes; +code_to_plant($C) -> clover; +code_to_plant($G) -> grass. 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/rebar.config b/exercises/practice/kindergarten-garden/rebar.config new file mode 100644 index 00000000..db5d9076 --- /dev/null +++ b/exercises/practice/kindergarten-garden/rebar.config @@ -0,0 +1,30 @@ +%% Erlang compiler options +{erl_opts, [debug_info, warnings_as_errors]}. + +{deps, [{erl_exercism, "0.1.2"}]}. + +{dialyzer, [ + {warnings, [underspecs, no_return]}, + {get_warnings, true}, + {plt_apps, top_level_deps}, % top_level_deps | all_deps + {plt_extra_apps, []}, + {plt_location, local}, % local | "/my/file/name" + {plt_prefix, "rebar3"}, + {base_plt_apps, [stdlib, kernel, crypto]}, + {base_plt_location, global}, % global | "/my/file/name" + {base_plt_prefix, "rebar3"} +]}. + +%% eunit:test(Tests) +{eunit_tests, []}. +%% Options for eunit:test(Tests, Opts) +{eunit_opts, [verbose]}. + +%% == xref == + +{xref_warnings, true}. + +%% xref checks to run +{xref_checks, [undefined_function_calls, undefined_functions, + locals_not_used, exports_not_used, + deprecated_function_calls, deprecated_functions]}. diff --git a/exercises/practice/kindergarten-garden/src/kindergarten_garden.app.src b/exercises/practice/kindergarten-garden/src/kindergarten_garden.app.src new file mode 100644 index 00000000..3785fea7 --- /dev/null +++ b/exercises/practice/kindergarten-garden/src/kindergarten_garden.app.src @@ -0,0 +1,9 @@ +{application, kindergarten_garden, + [{description, "exercism.org - kindergarten-garden"}, + {vsn, "0.0.1"}, + {modules, []}, + {registered, []}, + {applications, [kernel, + stdlib]}, + {env, []} + ]}. diff --git a/exercises/practice/kindergarten-garden/src/kindergarten_garden.erl b/exercises/practice/kindergarten-garden/src/kindergarten_garden.erl new file mode 100644 index 00000000..a68dd172 --- /dev/null +++ b/exercises/practice/kindergarten-garden/src/kindergarten_garden.erl @@ -0,0 +1,6 @@ +-module(kindergarten_garden). + +-export([plants/2]). + + +plants(_Garden, _Student) -> undefined. diff --git a/exercises/practice/kindergarten-garden/test/kindergarten_garden_tests.erl b/exercises/practice/kindergarten-garden/test/kindergarten_garden_tests.erl new file mode 100644 index 00000000..431228e5 --- /dev/null +++ b/exercises/practice/kindergarten-garden/test/kindergarten_garden_tests.erl @@ -0,0 +1,92 @@ +-module(kindergarten_garden_tests). + +-include_lib("erl_exercism/include/exercism.hrl"). +-include_lib("eunit/include/eunit.hrl"). + + + + +'1_garden_with_single_student_test_'() -> + {"Garden with single student", + ?_assertEqual([radishes, clover, grass, grass], + kindergarten_garden:plants("RC\nGG", alice))}. + +'2_different_garden_with_single_student_test_'() -> + {"Different garden with single student", + ?_assertEqual([violets, clover, radishes, clover], + kindergarten_garden:plants("VC\nRC", alice))}. + +'3_garden_with_two_students_test_'() -> + {"Garden with two students", + ?_assertEqual([clover, grass, radishes, clover], + kindergarten_garden:plants("VVCG\nVVRC", bob))}. + +'4_Multiple_students_second_students_garden_test_'() -> + {"Multiple students - second student's garden", + ?_assertEqual([clover, clover, clover, clover], + kindergarten_garden:plants("VVCCGG\nVVCCGG", bob))}. + +'5_Multiple_students_third_students_garden_test_'() -> + {"Multiple students - third student's garden", + ?_assertEqual([grass, grass, grass, grass], + kindergarten_garden:plants("VVCCGG\nVVCCGG", charlie))}. + +'6_full_garden_for_alice_test_'() -> + {"Full garden - for Alice", + ?_assertEqual([violets, radishes, violets, radishes], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", alice))}. + +'7_full_garden_for_bob_test_'() -> + {"Full garden - for Bob", + ?_assertEqual([clover, grass, clover, clover], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", bob))}. + +'8_full_garden_for_charlie_test_'() -> + {"Full garden - for Charlie", + ?_assertEqual([violets, violets, clover, grass], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", charlie))}. + +'9_full_garden_for_david_test_'() -> + {"Full garden - for David", + ?_assertEqual([radishes, violets, clover, radishes], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", david))}. + +'10_full_garden_for_eve_test_'() -> + {"Full garden - for Eve", + ?_assertEqual([clover, grass, radishes, grass], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", eve))}. + +'11_full_garden_for_fred_test_'() -> + {"Full garden - for Fred", + ?_assertEqual([grass, clover, violets, clover], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", fred))}. + +'12_full_garden_for_ginny_test_'() -> + {"Full garden - for Ginny", + ?_assertEqual([clover, grass, grass, clover], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", ginny))}. + +'13_full_garden_for_harriet_test_'() -> + {"Full garden - for Harriet", + ?_assertEqual([violets, radishes, radishes, violets], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", harriet))}. + +'14_full_garden_for_ileana_test_'() -> + {"Full garden - for Ileana", + ?_assertEqual([grass, clover, violets, clover], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", ileana))}. + +'15_full_garden_for_joseph_test_'() -> + {"Full garden - for Joseph", + ?_assertEqual([violets, clover, violets, grass], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", joseph))}. + +'16_full_garden_for_kincaid_test_'() -> + {"Full garden - for Kincaid", + ?_assertEqual([grass, clover, clover, grass], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", kincaid))}. + +'17_full_garden_for_larry_test_'() -> + {"Full garden - for Larry", + ?_assertEqual([grass, violets, clover, violets], + kindergarten_garden:plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", larry))}. From 2d5e36d47aa3b61fe82af7f16e148dd8cf8420f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sat, 5 Apr 2025 22:29:32 -0700 Subject: [PATCH 2/2] Fix module name --- exercises/practice/kindergarten-garden/.meta/example.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/kindergarten-garden/.meta/example.erl b/exercises/practice/kindergarten-garden/.meta/example.erl index 3a5ed2e1..2bdaf72d 100644 --- a/exercises/practice/kindergarten-garden/.meta/example.erl +++ b/exercises/practice/kindergarten-garden/.meta/example.erl @@ -1,4 +1,4 @@ --module(kindergarten_garden). +-module(example). -export([plants/2]).