diff --git a/config.json b/config.json index d4c8ea4..c928e09 100644 --- a/config.json +++ b/config.json @@ -557,6 +557,14 @@ "logic" ] }, + { + "slug": "twelve-days", + "name": "Twelve Days", + "uuid": "c3493cdc-f5e6-4651-a311-e7855163ca79", + "practices": [], + "prerequisites": [], + "difficulty": 2 + }, { "slug": "two-fer", "name": "Two-Fer", diff --git a/exercises/practice/twelve-days/.docs/instructions.md b/exercises/practice/twelve-days/.docs/instructions.md new file mode 100644 index 0000000..83bb6e1 --- /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 0000000..154f891 --- /dev/null +++ b/exercises/practice/twelve-days/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "twelve_days.vim" + ], + "test": [ + "twelve_days.vader" + ], + "example": [ + ".meta/example.vim" + ] + }, + "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.vim b/exercises/practice/twelve-days/.meta/example.vim new file mode 100644 index 0000000..0555b1c --- /dev/null +++ b/exercises/practice/twelve-days/.meta/example.vim @@ -0,0 +1,42 @@ +let s:gifts = [ + \ 'a Partridge in a Pear Tree.', + \ 'two Turtle Doves,', + \ '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,'] + +let s:ordinals = [ + \ 'first', + \ 'second', + \ 'third', + \ 'fourth', + \ 'fifth', + \ 'sixth', + \ 'seventh', + \ 'eighth', + \ 'ninth', + \ 'tenth', + \ 'eleventh', + \ 'twelfth'] + +function! Recite(startVerse, endVerse) abort + let l:verses = [] + for l:current in range(a:startVerse, a:endVerse) + let l:availableGifts = reverse(s:gifts[0:l:current-1]) + if l:current > 1 + let l:availableGifts[-1] = 'and ' . l:availableGifts[-1] + endif + + let l:verse = 'On the ' . s:ordinals[l:current - 1] . ' day of Christmas my true love gave to me: ' . join(l:availableGifts, ' ') + call add(l:verses, l:verse) + endfor + + return join(l:verses, '\n') +endfunction diff --git a/exercises/practice/twelve-days/.meta/tests.toml b/exercises/practice/twelve-days/.meta/tests.toml new file mode 100644 index 0000000..01fbc03 --- /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.vader b/exercises/practice/twelve-days/twelve_days.vader new file mode 100644 index 0000000..681796c --- /dev/null +++ b/exercises/practice/twelve-days/twelve_days.vader @@ -0,0 +1,284 @@ +Execute (first day a partridge in a pear tree): + let g:expected = join([ + \ 'On the first day of Christmas my true love gave to me:', + \ 'a Partridge in a Pear Tree.'], ' ') + AssertEqual g:expected, Recite(1, 1) + +Execute (second day two turtle doves): + let g:expected = join([ + \ 'On the second day of Christmas my true love gave to me:', + \ 'two Turtle Doves,', + \ 'and a Partridge in a Pear Tree.'], ' ') + AssertEqual g:expected, Recite(2, 2) + +Execute (third day three french hens): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(3, 3) + +Execute (fourth day four calling birds): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(4, 4) + +Execute (fifth day five gold rings): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(5, 5) + +Execute (sixth day six geese-a-laying): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(6, 6) + +Execute (seventh day seven swans-a-swimming): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(7, 7) + +Execute (eighth day eight maids-a-milking): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(8, 8) + +Execute (ninth day nine ladies dancing): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(9, 9) + +Execute (tenth day ten lords-a-leaping): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(10, 10) + +Execute (eleventh day eleven pipers piping): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(11, 11) + +Execute (twelfth day twelve drummers drumming): + let g:expected = join([ + \ '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.'], ' ') + AssertEqual g:expected, Recite(12, 12) + +Execute (recites first three verses of the song): + let g:expected = join([ + \ join([ + \ 'On the first day of Christmas my true love gave to me:', + \ 'a Partridge in a Pear Tree.'], ' '), + \ join([ + \ 'On the second day of Christmas my true love gave to me:', + \ 'two Turtle Doves,', + \ 'and a Partridge in a Pear Tree.'], ' '), + \ join([ + \ '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.'], ' ')], '\n') + AssertEqual g:expected, Recite(1, 3) + +Execute (recites three verses from the middle of the song): + let g:expected = join([ + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' ')], '\n') + AssertEqual g:expected, Recite(4, 6) + +Execute (recites the whole song): + let g:expected = join([ + \ join([ + \ 'On the first day of Christmas my true love gave to me:', + \ 'a Partridge in a Pear Tree.'], ' '), + \ join([ + \ 'On the second day of Christmas my true love gave to me:', + \ 'two Turtle Doves,', + \ 'and a Partridge in a Pear Tree.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' '), + \ join([ + \ '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.'], ' ')], '\n') + AssertEqual g:expected, Recite(1, 12) diff --git a/exercises/practice/twelve-days/twelve_days.vim b/exercises/practice/twelve-days/twelve_days.vim new file mode 100644 index 0000000..6d718bb --- /dev/null +++ b/exercises/practice/twelve-days/twelve_days.vim @@ -0,0 +1,11 @@ +" +" Recite the Twelve Days of Christmas from the given start verse to the end verse. +" +" Example: +" :echo Recite(1, 2) +" 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. +" +function! Recite(startVerse, endVerse) abort + " your code goes here +endfunction