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
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@
"prerequisites": [],
"difficulty": 5
},
{
"slug": "twelve-days",
"name": "Twelve Days",
"uuid": "ff75a702-38b8-4d86-a384-ce019c067589",
"practices": [],
"prerequisites": [],
"difficulty": 5
},
{
"slug": "acronym",
"name": "Acronym",
Expand Down
36 changes: 36 additions & 0 deletions exercises/practice/twelve-days/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Instructions

Your task in this exercise is to write code that returns the lyrics of the song: "The Twelve Days of Christmas."

"The Twelve Days of Christmas" is a common English Christmas carol.
Each subsequent verse of the song builds on the previous verse.

The lyrics your code returns should _exactly_ match the full song text shown below.

## Lyrics

```text
On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.

On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.

On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
```
19 changes: 19 additions & 0 deletions exercises/practice/twelve-days/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"jimmytty"
],
"files": {
"solution": [
"twelve-days.sql"
],
"test": [
"twelve-days_test.sql"
],
"example": [
".meta/example.sql"
]
},
"blurb": "Output the lyrics to 'The Twelve Days of Christmas'.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song)"
}
52 changes: 52 additions & 0 deletions exercises/practice/twelve-days/.meta/example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
DROP TABLE IF EXISTS inputs;
CREATE TEMPORARY TABLE inputs (
idx INTEGER NOT NULL,
ordinal TEXT NOT NULL,
item TEXT NOT NULL
);
INSERT INTO inputs (idx, ordinal, item)
VALUES
( 1, 'first', 'a Partridge in a Pear Tree'),
( 2, 'second', 'two Turtle Doves' ),
( 3, 'third', 'three French Hens' ),
( 4, 'fourth', 'four Calling Birds' ),
( 5, 'fifth', 'five Gold Rings' ),
( 6, 'sixth', 'six Geese-a-Laying' ),
( 7, 'seventh', 'seven Swans-a-Swimming' ),
( 8, 'eighth', 'eight Maids-a-Milking' ),
( 9, 'ninth', 'nine Ladies Dancing' ),
(10, 'tenth', 'ten Lords-a-Leaping' ),
(11, 'eleventh', 'eleven Pipers Piping' ),
(12, 'twelfth', 'twelve Drummers Drumming' );

DROP TABLE IF EXISTS verses;
CREATE TEMPORARY TABLE verses AS
SELECT idx,
PRINTF(
'On the %s day of Christmas my true love gave to me: %s.',
ordinal,
items
) AS verse
FROM (
SELECT
idx, ordinal,
GROUP_CONCAT(item, IIF(idx = 1, ', and ', ', '))
OVER(
ORDER BY idx DESC ROWS BETWEEN 0 PRECEDING AND 12 FOLLOWING
) items
FROM inputs
ORDER BY idx
)
;

UPDATE "twelve-days"
SET result = (
SELECT GROUP_CONCAT(verse, CHAR(10))
FROM (
SELECT verse
FROM verses
WHERE idx BETWEEN start_verse AND end_verse
ORDER BY idx
)
)
;
55 changes: 55 additions & 0 deletions exercises/practice/twelve-days/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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.

[c0b5a5e6-c89d-49b1-a6b2-9f523bff33f7]
description = "verse -> first day a partridge in a pear tree"

[1c64508a-df3d-420a-b8e1-fe408847854a]
description = "verse -> second day two turtle doves"

[a919e09c-75b2-4e64-bb23-de4a692060a8]
description = "verse -> third day three french hens"

[9bed8631-ec60-4894-a3bb-4f0ec9fbe68d]
description = "verse -> fourth day four calling birds"

[cf1024f0-73b6-4545-be57-e9cea565289a]
description = "verse -> fifth day five gold rings"

[50bd3393-868a-4f24-a618-68df3d02ff04]
description = "verse -> sixth day six geese-a-laying"

[8f29638c-9bf1-4680-94be-e8b84e4ade83]
description = "verse -> seventh day seven swans-a-swimming"

[7038d6e1-e377-47ad-8c37-10670a05bc05]
description = "verse -> eighth day eight maids-a-milking"

[37a800a6-7a56-4352-8d72-0f51eb37cfe8]
description = "verse -> ninth day nine ladies dancing"

[10b158aa-49ff-4b2d-afc3-13af9133510d]
description = "verse -> tenth day ten lords-a-leaping"

[08d7d453-f2ba-478d-8df0-d39ea6a4f457]
description = "verse -> eleventh day eleven pipers piping"

[0620fea7-1704-4e48-b557-c05bf43967f0]
description = "verse -> twelfth day twelve drummers drumming"

[da8b9013-b1e8-49df-b6ef-ddec0219e398]
description = "lyrics -> recites first three verses of the song"

[c095af0d-3137-4653-ad32-bfb899eda24c]
description = "lyrics -> recites three verses from the middle of the song"

[20921bc9-cc52-4627-80b3-198cbbfcf9b7]
description = "lyrics -> recites the whole song"
9 changes: 9 additions & 0 deletions exercises/practice/twelve-days/create_fixture.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP TABLE IF EXISTS "twelve-days";
CREATE TABLE "twelve-days" (
start_verse INTEGER NOT NULL,
end_verse INTEGER NOT NULL,
result TEXT
);

.mode csv
.import ./data.csv "twelve-days"
36 changes: 36 additions & 0 deletions exercises/practice/twelve-days/create_test_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP TABLE IF EXISTS tests;
CREATE TABLE IF NOT EXISTS tests (
-- uuid and description are taken from the test.toml file
uuid TEXT PRIMARY KEY,
description 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
start_verse INTEGER NOT NULL,
end_verse INTEGER NOT NULL,
expected TEXT NOT NULL
);

INSERT INTO tests (uuid, description, start_verse, end_verse, expected)
VALUES
('c0b5a5e6-c89d-49b1-a6b2-9f523bff33f7', 'first day a partridge in a pear tree', 1, 1, 'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.'),
('1c64508a-df3d-420a-b8e1-fe408847854a', 'second day two turtle doves', 2, 2, 'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.'),
('a919e09c-75b2-4e64-bb23-de4a692060a8', 'third day three french hens', 3, 3, 'On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('9bed8631-ec60-4894-a3bb-4f0ec9fbe68d', 'fourth day four calling birds', 4, 4, 'On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('cf1024f0-73b6-4545-be57-e9cea565289a', 'fifth day five gold rings', 5, 5, 'On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('50bd3393-868a-4f24-a618-68df3d02ff04', 'sixth day six geese-a-laying', 6, 6, 'On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('8f29638c-9bf1-4680-94be-e8b84e4ade83', 'seventh day seven swans-a-swimming', 7, 7, 'On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('7038d6e1-e377-47ad-8c37-10670a05bc05', 'eighth day eight maids-a-milking', 8, 8, 'On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('37a800a6-7a56-4352-8d72-0f51eb37cfe8', 'ninth day nine ladies dancing', 9, 9, 'On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('10b158aa-49ff-4b2d-afc3-13af9133510d', 'tenth day ten lords-a-leaping', 10, 10, 'On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('08d7d453-f2ba-478d-8df0-d39ea6a4f457', 'eleventh day eleven pipers piping', 11, 11, 'On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('0620fea7-1704-4e48-b557-c05bf43967f0', 'twelfth day twelve drummers drumming', 12, 12, 'On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('da8b9013-b1e8-49df-b6ef-ddec0219e398', 'recites first three verses of the song', 1, 3, 'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\nOn the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\nOn the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('c095af0d-3137-4653-ad32-bfb899eda24c', 'recites three verses from the middle of the song', 4, 6, 'On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.'),
('20921bc9-cc52-4627-80b3-198cbbfcf9b7', 'recites the whole song', 1, 12, 'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\nOn the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\nOn the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\nOn the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.');

UPDATE tests SET expected = REPLACE(expected, '\n', CHAR(10));
15 changes: 15 additions & 0 deletions exercises/practice/twelve-days/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
1,1,
2,2,
3,3,
4,4,
5,5,
6,6,
7,7,
8,8,
9,9,
10,10,
11,11,
12,12,
1,3,
4,6,
1,12,
8 changes: 8 additions & 0 deletions exercises/practice/twelve-days/twelve-days.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Schema:
-- CREATE TABLE "twelve-days" (
-- start_verse INTEGER NOT NULL,
-- end_verse INTEGER NOT NULL,
-- result TEXT
-- );
--
-- Task: update the twelve-days table and set result bases on the start_verse and end_verse.
40 changes: 40 additions & 0 deletions exercises/practice/twelve-days/twelve-days_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- 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 ./twelve-days.sql
.output

-- Create a clean testing environment:
.read ./create_test_table.sql

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

-- Update message for failed tests to give helpful information:
UPDATE tests
SET message = (
'Result for "'
|| PRINTF('start_verse: %d, end_verse: %d', tests.start_verse, tests.end_verse)
|| '"'
|| ' is <' || COALESCE(actual.result, 'NULL')
|| '> but should be <' || tests.expected || '>'
)
FROM (SELECT start_verse, end_verse, result FROM "twelve-days") AS actual
WHERE (actual.start_verse, actual.end_verse) = (tests.start_verse, tests.end_verse) AND tests.status = 'fail';

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

-- Display test results in readable form for the student:
.mode table
SELECT description, status, message
FROM tests;