Skip to content

Commit 8fb9f56

Browse files
authored
bottle song (#1583)
* bottle song * added changes to config.json * deprecated beer song
1 parent c63dcd9 commit 8fb9f56

File tree

15 files changed

+453
-0
lines changed

15 files changed

+453
-0
lines changed

config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@
892892
"practices": [],
893893
"prerequisites": [],
894894
"difficulty": 5,
895+
"status": "deprecated",
895896
"topics": [
896897
"conditionals",
897898
"loops",
@@ -1293,6 +1294,19 @@
12931294
"prerequisites": [],
12941295
"difficulty": 3
12951296
},
1297+
{
1298+
"slug": "bottle-song",
1299+
"name": "Bottle Song",
1300+
"uuid": "6bcfe2b6-e555-4c90-8c80-168730dd5ad3",
1301+
"practices": [],
1302+
"prerequisites": [],
1303+
"topics": [
1304+
"conditionals",
1305+
"loops",
1306+
"strings"
1307+
],
1308+
"difficulty": 3
1309+
},
12961310
{
12971311
"slug": "rotational-cipher",
12981312
"name": "Rotational Cipher",
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"authors": [
3+
"Budmin"
4+
],
5+
"files": {
6+
"solution": [
7+
"bottle-song.ts"
8+
],
9+
"test": [
10+
"bottle-song.test.ts"
11+
],
12+
"example": [
13+
".meta/proof.ci.ts"
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+
}
20+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const NUMBERS = [
2+
"no",
3+
"One",
4+
"Two",
5+
"Three",
6+
"Four",
7+
"Five",
8+
"Six",
9+
"Seven",
10+
"Eight",
11+
"Nine",
12+
"Ten",
13+
]
14+
15+
16+
export const recite = (initialBottleCount: number, takeDownCount = 1): string[] => {
17+
const out: string[] = []
18+
19+
for(let i = initialBottleCount; i > initialBottleCount - takeDownCount; i--) {
20+
const currentBottles = i === 1 ? 'bottle' : 'bottles'
21+
const nextBottles = i-1 === 1 ? 'bottle' : 'bottles'
22+
23+
out.push(...[
24+
...(Array(2).fill(`${NUMBERS[i]} green ${currentBottles} hanging on the wall,`)),
25+
`And if one green bottle should accidentally fall,`,
26+
`There'll be ${NUMBERS[i-1].toLowerCase()} green ${nextBottles} hanging on the wall.`
27+
])
28+
29+
if (initialBottleCount - takeDownCount !== i -1) {
30+
out.push('')
31+
}
32+
33+
}
34+
35+
return out
36+
}
37+
38+
39+
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"arcanis.vscode-zipfs",
4+
"dbaeumer.vscode-eslint",
5+
"esbenp.prettier-vscode"
6+
]
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cSpell.words": ["exercism"],
3+
"search.exclude": {
4+
"**/.yarn": true,
5+
"**/.pnp.*": true
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
compressionLevel: mixed
2+
3+
enableGlobalCache: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
// eslint-disable-next-line @typescript-eslint/no-require-imports
3+
presets: [[require('@exercism/babel-preset-typescript'), { corejs: '3.38' }]],
4+
plugins: [],
5+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import { describe, expect, it, xit } from '@jest/globals'
2+
import { recite } from './bottle-song.ts'
3+
4+
describe('Bottle Song', () => {
5+
describe('verse', () => {
6+
describe('single verse', () => {
7+
it('first generic verse', () => {
8+
const expected = [
9+
`Ten green bottles hanging on the wall,`,
10+
`Ten green bottles hanging on the wall,`,
11+
`And if one green bottle should accidentally fall,`,
12+
`There'll be nine green bottles hanging on the wall.`,
13+
]
14+
expect(recite(10, 1)).toEqual(expected)
15+
})
16+
17+
xit('last generic verse', () => {
18+
const expected = [
19+
`Three green bottles hanging on the wall,`,
20+
`Three green bottles hanging on the wall,`,
21+
`And if one green bottle should accidentally fall,`,
22+
`There'll be two green bottles hanging on the wall.`,
23+
]
24+
expect(recite(3, 1)).toEqual(expected)
25+
})
26+
27+
xit('verse with 2 bottles', () => {
28+
const expected = [
29+
`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+
]
34+
expect(recite(2, 1)).toEqual(expected)
35+
})
36+
37+
xit('verse with 1 bottle', () => {
38+
const expected = [
39+
`One green bottle hanging on the wall,`,
40+
`One green bottle hanging on the wall,`,
41+
`And if one green bottle should accidentally fall,`,
42+
`There'll be no green bottles hanging on the wall.`,
43+
]
44+
expect(recite(1, 1)).toEqual(expected)
45+
})
46+
})
47+
})
48+
49+
describe('lyrics', () => {
50+
describe('multiple verses', () => {
51+
xit('first two verses', () => {
52+
const expected = [
53+
`Ten green bottles hanging on the wall,`,
54+
`Ten green bottles hanging on the wall,`,
55+
`And if one green bottle should accidentally fall,`,
56+
`There'll be nine green bottles hanging on the wall.`,
57+
``,
58+
`Nine green bottles hanging on the wall,`,
59+
`Nine green bottles hanging on the wall,`,
60+
`And if one green bottle should accidentally fall,`,
61+
`There'll be eight green bottles hanging on the wall.`,
62+
]
63+
expect(recite(10, 2)).toEqual(expected)
64+
})
65+
66+
xit('last three verses', () => {
67+
const expected = [
68+
`Three green bottles hanging on the wall,`,
69+
`Three green bottles hanging on the wall,`,
70+
`And if one green bottle should accidentally fall,`,
71+
`There'll be two green bottles hanging on the wall.`,
72+
``,
73+
`Two green bottles hanging on the wall,`,
74+
`Two green bottles hanging on the wall,`,
75+
`And if one green bottle should accidentally fall,`,
76+
`There'll be one green bottle hanging on the wall.`,
77+
``,
78+
`One green bottle hanging on the wall,`,
79+
`One green bottle hanging on the wall,`,
80+
`And if one green bottle should accidentally fall,`,
81+
`There'll be no green bottles hanging on the wall.`,
82+
]
83+
expect(recite(3, 3)).toEqual(expected)
84+
})
85+
86+
xit('all verses', () => {
87+
const expected = [
88+
`Ten green bottles hanging on the wall,`,
89+
`Ten green bottles hanging on the wall,`,
90+
`And if one green bottle should accidentally fall,`,
91+
`There'll be nine green bottles hanging on the wall.`,
92+
``,
93+
`Nine green bottles hanging on the wall,`,
94+
`Nine green bottles hanging on the wall,`,
95+
`And if one green bottle should accidentally fall,`,
96+
`There'll be eight green bottles hanging on the wall.`,
97+
``,
98+
`Eight green bottles hanging on the wall,`,
99+
`Eight green bottles hanging on the wall,`,
100+
`And if one green bottle should accidentally fall,`,
101+
`There'll be seven green bottles hanging on the wall.`,
102+
``,
103+
`Seven green bottles hanging on the wall,`,
104+
`Seven green bottles hanging on the wall,`,
105+
`And if one green bottle should accidentally fall,`,
106+
`There'll be six green bottles hanging on the wall.`,
107+
``,
108+
`Six green bottles hanging on the wall,`,
109+
`Six green bottles hanging on the wall,`,
110+
`And if one green bottle should accidentally fall,`,
111+
`There'll be five green bottles hanging on the wall.`,
112+
``,
113+
`Five green bottles hanging on the wall,`,
114+
`Five green bottles hanging on the wall,`,
115+
`And if one green bottle should accidentally fall,`,
116+
`There'll be four green bottles hanging on the wall.`,
117+
``,
118+
`Four green bottles hanging on the wall,`,
119+
`Four green bottles hanging on the wall,`,
120+
`And if one green bottle should accidentally fall,`,
121+
`There'll be three green bottles hanging on the wall.`,
122+
``,
123+
`Three green bottles hanging on the wall,`,
124+
`Three green bottles hanging on the wall,`,
125+
`And if one green bottle should accidentally fall,`,
126+
`There'll be two green bottles hanging on the wall.`,
127+
``,
128+
`Two green bottles hanging on the wall,`,
129+
`Two green bottles hanging on the wall,`,
130+
`And if one green bottle should accidentally fall,`,
131+
`There'll be one green bottle hanging on the wall.`,
132+
``,
133+
`One green bottle hanging on the wall,`,
134+
`One green bottle hanging on the wall,`,
135+
`And if one green bottle should accidentally fall,`,
136+
`There'll be no green bottles hanging on the wall.`,
137+
]
138+
expect(recite(10, 10)).toEqual(expected)
139+
})
140+
})
141+
})
142+
})

0 commit comments

Comments
 (0)