From 12e6b7df14f2873ca7be648ff5b6fcc880985e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sun, 7 Jul 2024 23:40:31 -0700 Subject: [PATCH] Add kindergarten-garden (#259) --- 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.lfe | 37 ++++++++ .../kindergarten-garden/.meta/tests.toml | 61 ++++++++++++++ .../practice/kindergarten-garden/Makefile | 21 +++++ .../practice/kindergarten-garden/rebar.config | 11 +++ .../practice/kindergarten-garden/rebar.lock | 8 ++ .../src/kindergarten-garden.app.src | 11 +++ .../src/kindergarten-garden.lfe | 4 + .../test/kindergarten-garden-tests.lfe | 84 +++++++++++++++++++ 12 files changed, 326 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.lfe create mode 100644 exercises/practice/kindergarten-garden/.meta/tests.toml create mode 100644 exercises/practice/kindergarten-garden/Makefile create mode 100644 exercises/practice/kindergarten-garden/rebar.config create mode 100644 exercises/practice/kindergarten-garden/rebar.lock create mode 100644 exercises/practice/kindergarten-garden/src/kindergarten-garden.app.src create mode 100644 exercises/practice/kindergarten-garden/src/kindergarten-garden.lfe create mode 100644 exercises/practice/kindergarten-garden/test/kindergarten-garden-tests.lfe diff --git a/config.json b/config.json index d8ccef4d..4efa4986 100644 --- a/config.json +++ b/config.json @@ -427,6 +427,14 @@ "prerequisites": [], "difficulty": 5 }, + { + "slug": "kindergarten-garden", + "name": "Kindergarten Garden", + "uuid": "a595aa35-6947-4c9c-af31-ec099f7dd582", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, { "slug": "largest-series-product", "name": "Largest Series Product", 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..c4ec89e8 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "src/kindergarten-garden.lfe" + ], + "test": [ + "test/kindergarten-garden-tests.lfe" + ], + "example": [ + ".meta/example.lfe" + ] + }, + "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.lfe b/exercises/practice/kindergarten-garden/.meta/example.lfe new file mode 100644 index 00000000..853f80b0 --- /dev/null +++ b/exercises/practice/kindergarten-garden/.meta/example.lfe @@ -0,0 +1,37 @@ +(defmodule kindergarten-garden + (export (plants 2))) + +(defun plants (garden student) + (let ((diagram (parse garden)) + (index (position-of student))) + (lists:foldl (lambda (row acc) + (let ((first-cup (lists:nth index row)) + (second-cup (lists:nth (+ 1 index) row))) + (lists:append acc (list first-cup second-cup)))) + '() + diagram))) + +(defun parse (garden) + (let ((rows (string:split garden "\n")) + (get-code (lambda (chr) (plant-codes chr)))) + (lists:map (lambda (row) (lists:map get-code row)) rows))) + +(defun position-of + (("Alice") 1) + (("Bob") 3) + (("Charlie") 5) + (("David") 7) + (("Eve") 9) + (("Fred") 11) + (("Ginny") 13) + (("Harriet") 15) + (("Ileana") 17) + (("Joseph") 19) + (("Kincaid") 21) + (("Larry") 23)) + +(defun plant-codes + ((#\V) "violets") + ((#\R) "radishes") + ((#\C) "clover") + ((#\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/Makefile b/exercises/practice/kindergarten-garden/Makefile new file mode 100644 index 00000000..fbb5a7de --- /dev/null +++ b/exercises/practice/kindergarten-garden/Makefile @@ -0,0 +1,21 @@ +ERL := $(shell which erl) +REBAR3 := $(shell which rebar3) + +null := +space := $(null) # +comma := , + +ifeq ($(ERL),) + $(error Can't find Erlang executable 'erl') +else ifeq ($(REBAR3),) + $(error Can't find rebar3) +endif + +compile: ; $(REBAR3) compile + +clean: ; $(REBAR3) clean + +.PHONY: test +test: + $(REBAR3) eunit \ + -m $(subst $(space),$(comma),$(basename $(notdir $(wildcard test/*.lfe)))) diff --git a/exercises/practice/kindergarten-garden/rebar.config b/exercises/practice/kindergarten-garden/rebar.config new file mode 100644 index 00000000..30257891 --- /dev/null +++ b/exercises/practice/kindergarten-garden/rebar.config @@ -0,0 +1,11 @@ +{plugins, [{rebar3_lfe, "0.4.10"}]}. + +{provider_hooks, [{post, [{compile, {lfe, compile}}]}]}. + +{deps, [{lfe, "2.1.3"}]}. + +{profiles, + [{test, + [{eunit_compile_opts, [{src_dirs, ["src", "test"]}]}, + {deps, + [{ltest, "0.13.8"}]}]}]}. diff --git a/exercises/practice/kindergarten-garden/rebar.lock b/exercises/practice/kindergarten-garden/rebar.lock new file mode 100644 index 00000000..45836829 --- /dev/null +++ b/exercises/practice/kindergarten-garden/rebar.lock @@ -0,0 +1,8 @@ +{"1.2.0", +[{<<"lfe">>,{pkg,<<"lfe">>,<<"2.1.3">>},0}]}. +[ +{pkg_hash,[ + {<<"lfe">>, <<"6EFCB2BBC1FFC21DC5D1C092F00EFDB397EAC889474AC5C86EDF78A3557CC730">>}]}, +{pkg_hash_ext,[ + {<<"lfe">>, <<"4E4BAD515A169AE418FEB7374EA1C8D741FAEA9D95E266CE343B45BCC377F55B">>}]} +]. 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..bf010f75 --- /dev/null +++ b/exercises/practice/kindergarten-garden/src/kindergarten-garden.app.src @@ -0,0 +1,11 @@ +%% -*- erlang -*- +{application, 'kindergarten-garden', + [{description, "exercism.org - kindergarten garden"}, + {vsn, "0.0.1"}, + {modules, + ['kindergarten-garden']}, + {registered, []}, + {applications, + [kernel, stdlib]}, + {included_applications, []}, + {env, []}]}. diff --git a/exercises/practice/kindergarten-garden/src/kindergarten-garden.lfe b/exercises/practice/kindergarten-garden/src/kindergarten-garden.lfe new file mode 100644 index 00000000..aaf701c0 --- /dev/null +++ b/exercises/practice/kindergarten-garden/src/kindergarten-garden.lfe @@ -0,0 +1,4 @@ +(defmodule kindergarten-garden + (export (plants 2))) + +; Please implement the exported function(s). diff --git a/exercises/practice/kindergarten-garden/test/kindergarten-garden-tests.lfe b/exercises/practice/kindergarten-garden/test/kindergarten-garden-tests.lfe new file mode 100644 index 00000000..7da62924 --- /dev/null +++ b/exercises/practice/kindergarten-garden/test/kindergarten-garden-tests.lfe @@ -0,0 +1,84 @@ +(defmodule kindergarten-garden-tests + (behaviour ltest-unit) + (export all)) + +(include-lib "ltest/include/ltest-macros.lfe") + +(deftest garden-with-single-student + (is-equal '("radishes" "clover" "grass" "grass") + (kindergarten-garden:plants "RC\nGG" "Alice"))) + +(deftest different-garden-with-single-student + (is-equal '("violets" "clover" "radishes" "clover") + (kindergarten-garden:plants "VC\nRC" "Alice"))) + +(deftest garden-with-two-students + (is-equal '("clover" "grass" "radishes" "clover") + (kindergarten-garden:plants "VVCG\nVVRC" "Bob"))) + +(deftest second-students-garden + (is-equal '("clover" "clover" "clover" "clover") + (kindergarten-garden:plants "VVCCGG\nVVCCGG" "Bob"))) + +(deftest third-students-garden + (is-equal '("grass" "grass" "grass" "grass") + (kindergarten-garden:plants "VVCCGG\nVVCCGG" "Charlie"))) + +(deftest for-Alice + (is-equal '("violets" "radishes" "violets" "radishes") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Alice"))) + +(deftest for-Bob + (is-equal '("clover" "grass" "clover" "clover") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Bob"))) + +(deftest for-Charlie + (is-equal '("violets" "violets" "clover" "grass") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Charlie"))) + +(deftest for-David + (is-equal '("radishes" "violets" "clover" "radishes") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "David"))) + +(deftest for-Eve + (is-equal '("clover" "grass" "radishes" "grass") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Eve"))) + +(deftest for-Fred + (is-equal '("grass" "clover" "violets" "clover") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Fred"))) + +(deftest for-Ginny + (is-equal '("clover" "grass" "grass" "clover") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Ginny"))) + +(deftest for-Harriet + (is-equal '("violets" "radishes" "radishes" "violets") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Harriet"))) + +(deftest for-Ileana + (is-equal '("grass" "clover" "violets" "clover") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Ileana"))) +(deftest for-Joseph + (is-equal '("violets" "clover" "violets" "grass") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Joseph"))) + +(deftest for-Kincaid-second-to-last-students-garden + (is-equal '("grass" "clover" "clover" "grass") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Kincaid"))) + +(deftest for-Larry-last-students-garden + (is-equal '("grass" "violets" "clover" "violets") + (kindergarten-garden:plants "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV" + "Larry")))