Skip to content

Commit 069dbcd

Browse files
Add bottle-song (#486)
1 parent 32e9e66 commit 069dbcd

File tree

7 files changed

+301
-0
lines changed

7 files changed

+301
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,14 @@
546546
"math"
547547
]
548548
},
549+
{
550+
"slug": "bottle-song",
551+
"name": "Bottle Song",
552+
"uuid": "7e6f3680-2906-414e-bc73-5c03985ab071",
553+
"practices": [],
554+
"prerequisites": [],
555+
"difficulty": 4
556+
},
549557
{
550558
"slug": "diamond",
551559
"name": "Diamond",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Instructions
2+
3+
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles.
4+
5+
Note that not all verses are identical.
6+
7+
```text
8+
Ten green bottles hanging on the wall,
9+
Ten green bottles hanging on the wall,
10+
And if one green bottle should accidentally fall,
11+
There'll be nine green bottles hanging on the wall.
12+
13+
Nine green bottles hanging on the wall,
14+
Nine green bottles hanging on the wall,
15+
And if one green bottle should accidentally fall,
16+
There'll be eight green bottles hanging on the wall.
17+
18+
Eight green bottles hanging on the wall,
19+
Eight green bottles hanging on the wall,
20+
And if one green bottle should accidentally fall,
21+
There'll be seven green bottles hanging on the wall.
22+
23+
Seven green bottles hanging on the wall,
24+
Seven green bottles hanging on the wall,
25+
And if one green bottle should accidentally fall,
26+
There'll be six green bottles hanging on the wall.
27+
28+
Six green bottles hanging on the wall,
29+
Six green bottles hanging on the wall,
30+
And if one green bottle should accidentally fall,
31+
There'll be five green bottles hanging on the wall.
32+
33+
Five green bottles hanging on the wall,
34+
Five green bottles hanging on the wall,
35+
And if one green bottle should accidentally fall,
36+
There'll be four green bottles hanging on the wall.
37+
38+
Four green bottles hanging on the wall,
39+
Four green bottles hanging on the wall,
40+
And if one green bottle should accidentally fall,
41+
There'll be three green bottles hanging on the wall.
42+
43+
Three green bottles hanging on the wall,
44+
Three green bottles hanging on the wall,
45+
And if one green bottle should accidentally fall,
46+
There'll be two green bottles hanging on the wall.
47+
48+
Two green bottles hanging on the wall,
49+
Two green bottles hanging on the wall,
50+
And if one green bottle should accidentally fall,
51+
There'll be one green bottle hanging on the wall.
52+
53+
One green bottle hanging on the wall,
54+
One green bottle hanging on the wall,
55+
And if one green bottle should accidentally fall,
56+
There'll be no green bottles hanging on the wall.
57+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"bottle-song.el"
8+
],
9+
"test": [
10+
"bottle-song-test.el"
11+
],
12+
"example": [
13+
".meta/example.el"
14+
]
15+
},
16+
"blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.",
17+
"source": "Wikipedia",
18+
"source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles"
19+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
;;; bottle-song.el --- Bottle Song (exercism) -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
5+
;;; Code:
6+
7+
8+
(defconst numbers ["No" "One" "Two" "Three" "Four" "Five" "Six" "Seven"
9+
"Eight" "Nine" "Ten"])
10+
11+
(defun line (bottles lower)
12+
(concat
13+
(if lower
14+
(downcase (aref numbers bottles))
15+
(aref numbers bottles))
16+
" green bottle"
17+
(if (= bottles 1)
18+
""
19+
"s")
20+
" hanging on the wall"
21+
(if lower
22+
"."
23+
",")))
24+
25+
(defun lyrics (bottles)
26+
(list
27+
(line bottles nil)
28+
(line bottles nil)
29+
"And if one green bottle should accidentally fall,"
30+
(concat "There'll be " (line (1- bottles) t))))
31+
32+
(defun recite (start-bottles take-down)
33+
(if (= take-down 1)
34+
(lyrics start-bottles)
35+
(append
36+
(lyrics start-bottles)
37+
(list "")
38+
(recite (1- start-bottles) (1- take-down)))))
39+
40+
41+
(provide 'bottle-song)
42+
;;; bottle-song.el ends here
43+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03]
13+
description = "verse -> single verse -> first generic verse"
14+
15+
[0f0aded3-472a-4c64-b842-18d4f1f5f030]
16+
description = "verse -> single verse -> last generic verse"
17+
18+
[f61f3c97-131f-459e-b40a-7428f3ed99d9]
19+
description = "verse -> single verse -> verse with 2 bottles"
20+
21+
[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0]
22+
description = "verse -> single verse -> verse with 1 bottle"
23+
24+
[a4a28170-83d6-4dc1-bd8b-319b6abb6a80]
25+
description = "lyrics -> multiple verses -> first two verses"
26+
27+
[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db]
28+
description = "lyrics -> multiple verses -> last three verses"
29+
30+
[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28]
31+
description = "lyrics -> multiple verses -> all verses"
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
;;; bottle-song-test.el --- Bottle Song (exercism) -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
5+
;;; Code:
6+
7+
8+
(load-file "bottle-song.el")
9+
(declare-function recite "bottle-song.el" (start-bottles take-down))
10+
11+
12+
(ert-deftest first-generic-verse ()
13+
(let ((expected '("Ten green bottles hanging on the wall,"
14+
"Ten green bottles hanging on the wall,"
15+
"And if one green bottle should accidentally fall,"
16+
"There'll be nine green bottles hanging on the wall.")))
17+
(should (equal (recite 10 1) expected))))
18+
19+
20+
(ert-deftest last-generic-verse ()
21+
(let ((expected '("Three green bottles hanging on the wall,"
22+
"Three green bottles hanging on the wall,"
23+
"And if one green bottle should accidentally fall,"
24+
"There'll be two green bottles hanging on the wall.")))
25+
(should (equal (recite 3 1) expected))))
26+
27+
28+
(ert-deftest verse-with-2-bottles ()
29+
(let ((expected '("Two green bottles hanging on the wall,"
30+
"Two green bottles hanging on the wall,"
31+
"And if one green bottle should accidentally fall,"
32+
"There'll be one green bottle hanging on the wall.")))
33+
(should (equal (recite 2 1) expected))))
34+
35+
36+
(ert-deftest verse-with-1-bottle ()
37+
(let ((expected '("One green bottle hanging on the wall,"
38+
"One green bottle hanging on the wall,"
39+
"And if one green bottle should accidentally fall,"
40+
"There'll be no green bottles hanging on the wall.")))
41+
(should (equal (recite 1 1) expected))))
42+
43+
44+
(ert-deftest first-two-verses ()
45+
(let ((expected '("Ten green bottles hanging on the wall,"
46+
"Ten green bottles hanging on the wall,"
47+
"And if one green bottle should accidentally fall,"
48+
"There'll be nine green bottles hanging on the wall."
49+
""
50+
"Nine green bottles hanging on the wall,"
51+
"Nine green bottles hanging on the wall,"
52+
"And if one green bottle should accidentally fall,"
53+
"There'll be eight green bottles hanging on the wall.")))
54+
(should (equal (recite 10 2) expected))))
55+
56+
57+
(ert-deftest last-three-verses ()
58+
(let ((expected '("Three green bottles hanging on the wall,"
59+
"Three green bottles hanging on the wall,"
60+
"And if one green bottle should accidentally fall,"
61+
"There'll be two green bottles hanging on the wall."
62+
""
63+
"Two green bottles hanging on the wall,"
64+
"Two green bottles hanging on the wall,"
65+
"And if one green bottle should accidentally fall,"
66+
"There'll be one green bottle hanging on the wall."
67+
""
68+
"One green bottle hanging on the wall,"
69+
"One green bottle hanging on the wall,"
70+
"And if one green bottle should accidentally fall,"
71+
"There'll be no green bottles hanging on the wall.")))
72+
(should (equal (recite 3 3) expected))))
73+
74+
75+
(ert-deftest all-verses ()
76+
(let ((expected '("Ten green bottles hanging on the wall,"
77+
"Ten green bottles hanging on the wall,"
78+
"And if one green bottle should accidentally fall,"
79+
"There'll be nine green bottles hanging on the wall."
80+
""
81+
"Nine green bottles hanging on the wall,"
82+
"Nine green bottles hanging on the wall,"
83+
"And if one green bottle should accidentally fall,"
84+
"There'll be eight green bottles hanging on the wall."
85+
""
86+
"Eight green bottles hanging on the wall,"
87+
"Eight green bottles hanging on the wall,"
88+
"And if one green bottle should accidentally fall,"
89+
"There'll be seven green bottles hanging on the wall."
90+
""
91+
"Seven green bottles hanging on the wall,"
92+
"Seven green bottles hanging on the wall,"
93+
"And if one green bottle should accidentally fall,"
94+
"There'll be six green bottles hanging on the wall."
95+
""
96+
"Six green bottles hanging on the wall,"
97+
"Six green bottles hanging on the wall,"
98+
"And if one green bottle should accidentally fall,"
99+
"There'll be five green bottles hanging on the wall."
100+
""
101+
"Five green bottles hanging on the wall,"
102+
"Five green bottles hanging on the wall,"
103+
"And if one green bottle should accidentally fall,"
104+
"There'll be four green bottles hanging on the wall."
105+
""
106+
"Four green bottles hanging on the wall,"
107+
"Four green bottles hanging on the wall,"
108+
"And if one green bottle should accidentally fall,"
109+
"There'll be three green bottles hanging on the wall."
110+
""
111+
"Three green bottles hanging on the wall,"
112+
"Three green bottles hanging on the wall,"
113+
"And if one green bottle should accidentally fall,"
114+
"There'll be two green bottles hanging on the wall."
115+
""
116+
"Two green bottles hanging on the wall,"
117+
"Two green bottles hanging on the wall,"
118+
"And if one green bottle should accidentally fall,"
119+
"There'll be one green bottle hanging on the wall."
120+
""
121+
"One green bottle hanging on the wall,"
122+
"One green bottle hanging on the wall,"
123+
"And if one green bottle should accidentally fall,"
124+
"There'll be no green bottles hanging on the wall.")))
125+
(should (equal (recite 10 10) expected))))
126+
127+
128+
(provide 'bottle-song-test)
129+
;;; bottle-song-test.el ends here
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
;;; bottle-song.el --- Bottle Song (exercism) -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
5+
;;; Code:
6+
7+
8+
(defun recite (start-bottles take-down)
9+
(error "Delete this S-Expression and write your own implementation"))
10+
11+
12+
(provide 'bottle-song)
13+
;;; bottle-song.el ends here
14+

0 commit comments

Comments
 (0)