Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.swp
.vscode
.DS_Store
bin/configlet
bin/configlet.exe
Expand Down
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@
"prerequisites": [],
"difficulty": 8
},
{
"slug": "kindergarten-garden",
"name": "Kindergarten Garden",
"uuid": "fb354d1a-c85d-42d0-b919-f554eaa27a08",
"practices": [],
"prerequisites": [],
"difficulty": 5
},
{
"slug": "roman-numerals",
"name": "Roman Numerals",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SQLite specific instructions

This exercise requires you set the `result` column of the `kindergarten-garden` table to the correct value based on the `diagram` and `student` columns.

## Table Schema

```sql
CREATE TABLE "kindergarten-garden" ("diagram" TEXT, "student" TEXT, "result" TEXT);
```
56 changes: 56 additions & 0 deletions exercises/practice/kindergarten-garden/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions exercises/practice/kindergarten-garden/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 22 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"authors": [
"Steffan153"
],
"files": {
"solution": [
"kindergarten-garden.sql"
],
"test": [
"kindergarten-garden_test.sql"
],
"example": [
".meta/example.sql"
],
"editor": [
"data.csv"
]
},
"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"
}
14 changes: 14 additions & 0 deletions exercises/practice/kindergarten-garden/.meta/example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
UPDATE "kindergarten-garden"
SET result = (
WITH plants(p) AS (
VALUES (1), (2), (1 + instr(diagram, char(10))), (2 + instr(diagram, char(10)))
)
SELECT group_concat(
CASE SUBSTR(diagram, (unicode(student) - 65) * 2 + p, 1)
WHEN 'G' THEN 'grass'
WHEN 'V' THEN 'violets'
WHEN 'C' THEN 'clover'
WHEN 'R' THEN 'radishes'
END
) FROM plants
);
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"
9 changes: 9 additions & 0 deletions exercises/practice/kindergarten-garden/create_fixture.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP TABLE IF EXISTS "kindergarten-garden";
CREATE TABLE "kindergarten-garden" (
"diagram" TEXT,
"student" TEXT,
"result" TEXT
);

.mode csv
.import ./data.csv kindergarten-garden
34 changes: 34 additions & 0 deletions exercises/practice/kindergarten-garden/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"RC
GG","Alice",""
"VC
RC","Alice",""
"VVCG
VVRC","Bob",""
"VVCCGG
VVCCGG","Bob",""
"VVCCGG
VVCCGG","Charlie",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Alice",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Bob",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Charlie",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","David",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Eve",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Fred",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Ginny",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Harriet",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Ileana",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Joseph",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Kincaid",""
"VRCGVVRVCGGCCGVRGCVCGCGV
VRCCCGCRRGVCGCRVVCVGCGCV","Larry",""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Schema: CREATE TABLE "kindergarten-garden" ("diagram" TEXT, "student" TEXT, "result" TEXT);
-- Task: update the kindergarten-garden table and set the result based on the diagram and student fields.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Setup test table and read in student solution:
.read ./test_setup.sql

-- Test cases:
INSERT INTO tests (name, uuid,
diagram, student, expected)
VALUES
('garden with single student', '1fc316ed-17ab-4fba-88ef-3ae78296b692',
'RC' || char(10) || 'GG', 'Alice', 'radishes,clover,grass,grass'),
('different garden with single student', 'acd19dc1-2200-4317-bc2a-08f021276b40',
'VC' || char(10) || 'RC', 'Alice', 'violets,clover,radishes,clover'),
('garden with two students', 'c376fcc8-349c-446c-94b0-903947315757',
'VVCG' || char(10) || 'VVRC', 'Bob', 'clover,grass,radishes,clover'),
('second student''s garden', '2d620f45-9617-4924-9d27-751c80d17db9',
'VVCCGG' || char(10) || 'VVCCGG', 'Bob', 'clover,clover,clover,clover'),
('third student''s garden', '57712331-4896-4364-89f8-576421d69c44',
'VVCCGG' || char(10) || 'VVCCGG', 'Charlie', 'grass,grass,grass,grass'),
('for Alice, first student''s garden', '149b4290-58e1-40f2-8ae4-8b87c46e765b',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Alice', 'violets,radishes,violets,radishes'),
('for Bob, second student''s garden', 'ba25dbbc-10bd-4a37-b18e-f89ecd098a5e',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Bob', 'clover,grass,clover,clover'),
('for Charlie', '566b621b-f18e-4c5f-873e-be30544b838c',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Charlie', 'violets,violets,clover,grass'),
('for David', '3ad3df57-dd98-46fc-9269-1877abf612aa',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'David', 'radishes,violets,clover,radishes'),
('for Eve', '0f0a55d1-9710-46ed-a0eb-399ba8c72db2',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Eve', 'clover,grass,radishes,grass'),
('for Fred', 'a7e80c90-b140-4ea1-aee3-f4625365c9a4',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Fred', 'grass,clover,violets,clover'),
('for Ginny', '9d94b273-2933-471b-86e8-dba68694c615',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Ginny', 'clover,grass,grass,clover'),
('for Harriet', 'f55bc6c2-ade8-4844-87c4-87196f1b7258',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Harriet', 'violets,radishes,radishes,violets'),
('for Ileana', '759070a3-1bb1-4dd4-be2c-7cce1d7679ae',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Ileana', 'grass,clover,violets,clover'),
('for Joseph', '78578123-2755-4d4a-9c7d-e985b8dda1c6',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Joseph', 'violets,clover,violets,grass'),
('for Kincaid, second to last student''s garden', '6bb66df7-f433-41ab-aec2-3ead6e99f65b',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Kincaid', 'grass,clover,clover,grass'),
('for Larry, last student''s garden', 'd7edec11-6488-418a-94e6-ed509e0fa7eb',
'VRCGVVRVCGGCCGVRGCVCGCGV' || char(10) || 'VRCCCGCRRGVCGCRVVCVGCGCV', 'Larry', 'grass,violets,clover,violets');

-- Comparison of user input and the tests updates the status for each test:
UPDATE tests
SET status = 'pass'
FROM (SELECT diagram, student, result FROM "kindergarten-garden") AS actual
WHERE (actual.diagram, actual.student, actual.result) = (tests.diagram, tests.student, tests.expected);

-- Write results and debug info:
.read ./test_reporter.sql
16 changes: 16 additions & 0 deletions exercises/practice/kindergarten-garden/test_reporter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Update message for failed tests to give helpful information:
UPDATE tests
SET message = 'Result for "' || tests.diagram || '" and "' || tests.student || '" is ' || actual.result || ', but should be ' || tests.expected
FROM (SELECT diagram, student, result FROM 'kindergarten-garden') AS actual
WHERE (actual.diagram, actual.student) = (tests.diagram, tests.student) AND tests.status = 'fail';

-- Save results to ./output.json (needed by the online test-runner)
.mode json
.once './output.json'
SELECT name, status, message, output, test_code, task_id
FROM tests;

-- Display test results in readable form for the student:
.mode table
SELECT name, status, message
FROM tests;
26 changes: 26 additions & 0 deletions exercises/practice/kindergarten-garden/test_setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Create database:
.read ./create_fixture.sql

-- Read user student solution and save any output as markdown in user_output.md:
.mode markdown
.output user_output.md
.read ./kindergarten-garden.sql
.output

-- Create a clean testing environment:
DROP TABLE IF EXISTS tests;
CREATE TABLE IF NOT EXISTS tests (
-- uuid and name (description) are taken from the test.toml file
uuid TEXT PRIMARY KEY,
name TEXT NOT NULL,
-- The following section is needed by the online test-runner
status TEXT DEFAULT 'fail',
message TEXT,
output TEXT,
test_code TEXT,
task_id INTEGER DEFAULT NULL,
-- Here are columns for the actual tests
diagram TEXT NOT NULL,
student TEXT NOT NULL,
expected TEXT NOT NULL
);