diff --git a/config.json b/config.json index 1b347a7f..49c34597 100644 --- a/config.json +++ b/config.json @@ -546,6 +546,14 @@ "math" ] }, + { + "slug": "bottle-song", + "name": "Bottle Song", + "uuid": "7e6f3680-2906-414e-bc73-5c03985ab071", + "practices": [], + "prerequisites": [], + "difficulty": 4 + }, { "slug": "diamond", "name": "Diamond", diff --git a/exercises/practice/bottle-song/.docs/instructions.md b/exercises/practice/bottle-song/.docs/instructions.md new file mode 100644 index 00000000..febdfc86 --- /dev/null +++ b/exercises/practice/bottle-song/.docs/instructions.md @@ -0,0 +1,57 @@ +# Instructions + +Recite the lyrics to that popular children's repetitive song: Ten Green Bottles. + +Note that not all verses are identical. + +```text +Ten green bottles hanging on the wall, +Ten green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be nine green bottles hanging on the wall. + +Nine green bottles hanging on the wall, +Nine green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be eight green bottles hanging on the wall. + +Eight green bottles hanging on the wall, +Eight green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be seven green bottles hanging on the wall. + +Seven green bottles hanging on the wall, +Seven green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be six green bottles hanging on the wall. + +Six green bottles hanging on the wall, +Six green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be five green bottles hanging on the wall. + +Five green bottles hanging on the wall, +Five green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be four green bottles hanging on the wall. + +Four green bottles hanging on the wall, +Four green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be three green bottles hanging on the wall. + +Three green bottles hanging on the wall, +Three green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be two green bottles hanging on the wall. + +Two green bottles hanging on the wall, +Two green bottles hanging on the wall, +And if one green bottle should accidentally fall, +There'll be one green bottle hanging on the wall. + +One green bottle hanging on the wall, +One green bottle hanging on the wall, +And if one green bottle should accidentally fall, +There'll be no green bottles hanging on the wall. +``` diff --git a/exercises/practice/bottle-song/.meta/config.json b/exercises/practice/bottle-song/.meta/config.json new file mode 100644 index 00000000..cbba3df1 --- /dev/null +++ b/exercises/practice/bottle-song/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "keiravillekode" + ], + "files": { + "solution": [ + "bottle-song.el" + ], + "test": [ + "bottle-song-test.el" + ], + "example": [ + ".meta/example.el" + ] + }, + "blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles" +} diff --git a/exercises/practice/bottle-song/.meta/example.el b/exercises/practice/bottle-song/.meta/example.el new file mode 100644 index 00000000..49658246 --- /dev/null +++ b/exercises/practice/bottle-song/.meta/example.el @@ -0,0 +1,43 @@ +;;; bottle-song.el --- Bottle Song (exercism) -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: + + +(defconst numbers ["No" "One" "Two" "Three" "Four" "Five" "Six" "Seven" + "Eight" "Nine" "Ten"]) + +(defun line (bottles lower) + (concat + (if lower + (downcase (aref numbers bottles)) + (aref numbers bottles)) + " green bottle" + (if (= bottles 1) + "" + "s") + " hanging on the wall" + (if lower + "." + ","))) + +(defun lyrics (bottles) + (list + (line bottles nil) + (line bottles nil) + "And if one green bottle should accidentally fall," + (concat "There'll be " (line (1- bottles) t)))) + +(defun recite (start-bottles take-down) + (if (= take-down 1) + (lyrics start-bottles) + (append + (lyrics start-bottles) + (list "") + (recite (1- start-bottles) (1- take-down))))) + + +(provide 'bottle-song) +;;; bottle-song.el ends here + diff --git a/exercises/practice/bottle-song/.meta/tests.toml b/exercises/practice/bottle-song/.meta/tests.toml new file mode 100644 index 00000000..1f6e40a3 --- /dev/null +++ b/exercises/practice/bottle-song/.meta/tests.toml @@ -0,0 +1,31 @@ +# 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. + +[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03] +description = "verse -> single verse -> first generic verse" + +[0f0aded3-472a-4c64-b842-18d4f1f5f030] +description = "verse -> single verse -> last generic verse" + +[f61f3c97-131f-459e-b40a-7428f3ed99d9] +description = "verse -> single verse -> verse with 2 bottles" + +[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0] +description = "verse -> single verse -> verse with 1 bottle" + +[a4a28170-83d6-4dc1-bd8b-319b6abb6a80] +description = "lyrics -> multiple verses -> first two verses" + +[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db] +description = "lyrics -> multiple verses -> last three verses" + +[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28] +description = "lyrics -> multiple verses -> all verses" diff --git a/exercises/practice/bottle-song/bottle-song-test.el b/exercises/practice/bottle-song/bottle-song-test.el new file mode 100644 index 00000000..2297f3f0 --- /dev/null +++ b/exercises/practice/bottle-song/bottle-song-test.el @@ -0,0 +1,129 @@ +;;; bottle-song-test.el --- Bottle Song (exercism) -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: + + +(load-file "bottle-song.el") +(declare-function recite "bottle-song.el" (start-bottles take-down)) + + +(ert-deftest first-generic-verse () + (let ((expected '("Ten green bottles hanging on the wall," + "Ten green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be nine green bottles hanging on the wall."))) + (should (equal (recite 10 1) expected)))) + + +(ert-deftest last-generic-verse () + (let ((expected '("Three green bottles hanging on the wall," + "Three green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be two green bottles hanging on the wall."))) + (should (equal (recite 3 1) expected)))) + + +(ert-deftest verse-with-2-bottles () + (let ((expected '("Two green bottles hanging on the wall," + "Two green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be one green bottle hanging on the wall."))) + (should (equal (recite 2 1) expected)))) + + +(ert-deftest verse-with-1-bottle () + (let ((expected '("One green bottle hanging on the wall," + "One green bottle hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be no green bottles hanging on the wall."))) + (should (equal (recite 1 1) expected)))) + + +(ert-deftest first-two-verses () + (let ((expected '("Ten green bottles hanging on the wall," + "Ten green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be nine green bottles hanging on the wall." + "" + "Nine green bottles hanging on the wall," + "Nine green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be eight green bottles hanging on the wall."))) + (should (equal (recite 10 2) expected)))) + + +(ert-deftest last-three-verses () + (let ((expected '("Three green bottles hanging on the wall," + "Three green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be two green bottles hanging on the wall." + "" + "Two green bottles hanging on the wall," + "Two green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be one green bottle hanging on the wall." + "" + "One green bottle hanging on the wall," + "One green bottle hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be no green bottles hanging on the wall."))) + (should (equal (recite 3 3) expected)))) + + +(ert-deftest all-verses () + (let ((expected '("Ten green bottles hanging on the wall," + "Ten green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be nine green bottles hanging on the wall." + "" + "Nine green bottles hanging on the wall," + "Nine green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be eight green bottles hanging on the wall." + "" + "Eight green bottles hanging on the wall," + "Eight green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be seven green bottles hanging on the wall." + "" + "Seven green bottles hanging on the wall," + "Seven green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be six green bottles hanging on the wall." + "" + "Six green bottles hanging on the wall," + "Six green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be five green bottles hanging on the wall." + "" + "Five green bottles hanging on the wall," + "Five green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be four green bottles hanging on the wall." + "" + "Four green bottles hanging on the wall," + "Four green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be three green bottles hanging on the wall." + "" + "Three green bottles hanging on the wall," + "Three green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be two green bottles hanging on the wall." + "" + "Two green bottles hanging on the wall," + "Two green bottles hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be one green bottle hanging on the wall." + "" + "One green bottle hanging on the wall," + "One green bottle hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be no green bottles hanging on the wall."))) + (should (equal (recite 10 10) expected)))) + + +(provide 'bottle-song-test) +;;; bottle-song-test.el ends here diff --git a/exercises/practice/bottle-song/bottle-song.el b/exercises/practice/bottle-song/bottle-song.el new file mode 100644 index 00000000..12d37578 --- /dev/null +++ b/exercises/practice/bottle-song/bottle-song.el @@ -0,0 +1,14 @@ +;;; bottle-song.el --- Bottle Song (exercism) -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: + + +(defun recite (start-bottles take-down) + (error "Delete this S-Expression and write your own implementation")) + + +(provide 'bottle-song) +;;; bottle-song.el ends here +