From ffc77dd8c4f0497d657d88586e2cdbf4b02a9c0c Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Sat, 28 Sep 2024 06:03:31 +1000 Subject: [PATCH 1/2] Add twelve-days exercise --- config.json | 8 ++ exercises/practice/twelve-days/.busted | 5 + .../twelve-days/.docs/instructions.md | 36 +++++ .../practice/twelve-days/.meta/config.json | 19 +++ .../practice/twelve-days/.meta/example.lua | 27 ++++ .../twelve-days/.meta/spec_generator.lua | 26 ++++ .../practice/twelve-days/.meta/tests.toml | 55 ++++++++ .../practice/twelve-days/twelve-days.lua | 5 + .../practice/twelve-days/twelve-days_spec.lua | 125 ++++++++++++++++++ 9 files changed, 306 insertions(+) create mode 100644 exercises/practice/twelve-days/.busted create mode 100644 exercises/practice/twelve-days/.docs/instructions.md create mode 100644 exercises/practice/twelve-days/.meta/config.json create mode 100644 exercises/practice/twelve-days/.meta/example.lua create mode 100644 exercises/practice/twelve-days/.meta/spec_generator.lua create mode 100644 exercises/practice/twelve-days/.meta/tests.toml create mode 100644 exercises/practice/twelve-days/twelve-days.lua create mode 100644 exercises/practice/twelve-days/twelve-days_spec.lua diff --git a/config.json b/config.json index 75e49843..fecadbaf 100644 --- a/config.json +++ b/config.json @@ -650,6 +650,14 @@ "exception_handling" ] }, + { + "slug": "twelve-days", + "name": "Twelve Days", + "uuid": "51ea559b-818b-47a9-91af-53772c46e171", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "word-count", "name": "Word Count", diff --git a/exercises/practice/twelve-days/.busted b/exercises/practice/twelve-days/.busted new file mode 100644 index 00000000..86b84e7c --- /dev/null +++ b/exercises/practice/twelve-days/.busted @@ -0,0 +1,5 @@ +return { + default = { + ROOT = { '.' } + } +} diff --git a/exercises/practice/twelve-days/.docs/instructions.md b/exercises/practice/twelve-days/.docs/instructions.md new file mode 100644 index 00000000..83bb6e19 --- /dev/null +++ b/exercises/practice/twelve-days/.docs/instructions.md @@ -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. +``` diff --git a/exercises/practice/twelve-days/.meta/config.json b/exercises/practice/twelve-days/.meta/config.json new file mode 100644 index 00000000..1c61cec4 --- /dev/null +++ b/exercises/practice/twelve-days/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "keiravillekode" + ], + "files": { + "solution": [ + "twelve-days.lua" + ], + "test": [ + "twelve-days_spec.lua" + ], + "example": [ + ".meta/example.lua" + ] + }, + "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)" +} diff --git a/exercises/practice/twelve-days/.meta/example.lua b/exercises/practice/twelve-days/.meta/example.lua new file mode 100644 index 00000000..66c822ba --- /dev/null +++ b/exercises/practice/twelve-days/.meta/example.lua @@ -0,0 +1,27 @@ +local function recite_verse(verse) + local lyrics = { + '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.' + } + return lyrics[verse] +end + +local function recite(start_verse, end_verse) + local result = {} + for verse = start_verse, end_verse do + table.insert(result, recite_verse(verse)) + end + return result +end + +return { recite = recite } diff --git a/exercises/practice/twelve-days/.meta/spec_generator.lua b/exercises/practice/twelve-days/.meta/spec_generator.lua new file mode 100644 index 00000000..8088c862 --- /dev/null +++ b/exercises/practice/twelve-days/.meta/spec_generator.lua @@ -0,0 +1,26 @@ +local map = function(t, f) + local mapped = {} + for i, v in ipairs(t) do + mapped[i] = f(v) + end + return mapped +end + +local function render_song(lines) + return table.concat(map(lines, function(line) + return '\'' .. line .. '\'' + end), ',\n') +end + +return { + module_name = 'twelve_days', + + generate_test = function(case) + local template = [[ + local expected = { + %s + } + assert.are.same(expected, twelve_days.recite(%d, %d))]] + return template:format(render_song(case.expected), case.input.startVerse, case.input.endVerse) + end +} diff --git a/exercises/practice/twelve-days/.meta/tests.toml b/exercises/practice/twelve-days/.meta/tests.toml new file mode 100644 index 00000000..01fbc03f --- /dev/null +++ b/exercises/practice/twelve-days/.meta/tests.toml @@ -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" diff --git a/exercises/practice/twelve-days/twelve-days.lua b/exercises/practice/twelve-days/twelve-days.lua new file mode 100644 index 00000000..4b53f282 --- /dev/null +++ b/exercises/practice/twelve-days/twelve-days.lua @@ -0,0 +1,5 @@ +local function recite(start_verse, end_verse) + +end + +return { recite = recite } diff --git a/exercises/practice/twelve-days/twelve-days_spec.lua b/exercises/practice/twelve-days/twelve-days_spec.lua new file mode 100644 index 00000000..0746dc48 --- /dev/null +++ b/exercises/practice/twelve-days/twelve-days_spec.lua @@ -0,0 +1,125 @@ +local twelve_days = require('twelve-days') + +describe('twelve-days', function() + describe('verse', function() + it('first day a partridge in a pear tree', function() + local expected = { 'On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.' } + assert.are.same(expected, twelve_days.recite(1, 1)) + end) + + it('second day two turtle doves', function() + local expected = { + 'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.' + } + assert.are.same(expected, twelve_days.recite(2, 2)) + end) + + it('third day three french hens', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(3, 3)) + end) + + it('fourth day four calling birds', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(4, 4)) + end) + + it('fifth day five gold rings', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(5, 5)) + end) + + it('sixth day six geese-a-laying', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(6, 6)) + end) + + it('seventh day seven swans-a-swimming', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(7, 7)) + end) + + it('eighth day eight maids-a-milking', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(8, 8)) + end) + + it('ninth day nine ladies dancing', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(9, 9)) + end) + + it('tenth day ten lords-a-leaping', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(10, 10)) + end) + + it('eleventh day eleven pipers piping', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(11, 11)) + end) + + it('twelfth day twelve drummers drumming', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(12, 12)) + end) + end) + + describe('lyrics', function() + it('recites first three verses of the song', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(1, 3)) + end) + + it('recites three verses from the middle of the song', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(4, 6)) + end) + + it('recites the whole song', function() + local expected = { + '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.' + } + assert.are.same(expected, twelve_days.recite(1, 12)) + end) + end) +end) From 6862ec13650b93883fcf2f97aee99c5cbec2981a Mon Sep 17 00:00:00 2001 From: Eric Willigers Date: Sat, 28 Sep 2024 13:20:03 +1000 Subject: [PATCH 2/2] Generate each verse --- .../practice/twelve-days/.meta/example.lua | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/exercises/practice/twelve-days/.meta/example.lua b/exercises/practice/twelve-days/.meta/example.lua index 66c822ba..e174c72d 100644 --- a/exercises/practice/twelve-days/.meta/example.lua +++ b/exercises/practice/twelve-days/.meta/example.lua @@ -1,19 +1,40 @@ local function recite_verse(verse) - local lyrics = { - '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.' + local ordinals = { + 'first', + 'second', + 'third', + 'fourth', + 'fifth', + 'sixth', + 'seventh', + 'eighth', + 'ninth', + 'tenth', + 'eleventh', + 'twelfth' } - return lyrics[verse] + + local gifts = { + 'a Partridge in a Pear Tree.', + 'two Turtle Doves, and', + 'three French Hens,', + 'four Calling Birds,', + 'five Gold Rings,', + 'six Geese-a-Laying,', + 'seven Swans-a-Swimming,', + 'eight Maids-a-Milking,', + 'nine Ladies Dancing,', + 'ten Lords-a-Leaping,', + 'eleven Pipers Piping,', + 'twelve Drummers Drumming,' + } + + local result = { 'On the', ordinals[verse], 'day of Christmas my true love gave to me:' } + for index = verse, 1, -1 do + table.insert(result, gifts[index]) + end + + return table.concat(result, ' ') end local function recite(start_verse, end_verse)