Skip to content

bottle song #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,19 @@
"prerequisites": [],
"difficulty": 3
},
{
"slug": "bottle-song",
"name": "Bottle Song",
"uuid": "6bcfe2b6-e555-4c90-8c80-168730dd5ad3",
"practices": [],
"prerequisites": [],
"topics": [
"conditionals",
"loops",
"strings"
],
"difficulty": 3
},
{
"slug": "rotational-cipher",
"name": "Rotational Cipher",
Expand Down
57 changes: 57 additions & 0 deletions exercises/practice/bottle-song/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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.
```
20 changes: 20 additions & 0 deletions exercises/practice/bottle-song/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"Budmin"
],
"files": {
"solution": [
"bottle-song.ts"
],
"test": [
"bottle-song.test.ts"
],
"example": [
".meta/proof.ci.ts"
]
},
"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"
}

39 changes: 39 additions & 0 deletions exercises/practice/bottle-song/.meta/proof.ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const NUMBERS = [
"no",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
]


export const recite = (initialBottleCount: number, takeDownCount = 1): string[] => {
const out: string[] = []

for(let i = initialBottleCount; i > initialBottleCount - takeDownCount; i--) {
const currentBottles = i === 1 ? 'bottle' : 'bottles'
const nextBottles = i-1 === 1 ? 'bottle' : 'bottles'

out.push(...[
...(Array(2).fill(`${NUMBERS[i]} green ${currentBottles} hanging on the wall,`)),
`And if one green bottle should accidentally fall,`,
`There'll be ${NUMBERS[i-1].toLowerCase()} green ${nextBottles} hanging on the wall.`
])

if (initialBottleCount - takeDownCount !== i -1) {
out.push('')
}

}

return out
}



31 changes: 31 additions & 0 deletions exercises/practice/bottle-song/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 7 additions & 0 deletions exercises/practice/bottle-song/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
7 changes: 7 additions & 0 deletions exercises/practice/bottle-song/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cSpell.words": ["exercism"],
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
}
}
3 changes: 3 additions & 0 deletions exercises/practice/bottle-song/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
compressionLevel: mixed

enableGlobalCache: true
5 changes: 5 additions & 0 deletions exercises/practice/bottle-song/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
// eslint-disable-next-line @typescript-eslint/no-require-imports
presets: [[require('@exercism/babel-preset-typescript'), { corejs: '3.38' }]],
plugins: [],
}
142 changes: 142 additions & 0 deletions exercises/practice/bottle-song/bottle-song.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { describe, expect, it, xit } from '@jest/globals'
import { recite } from './bottle-song.ts'

describe('Bottle Song', () => {
describe('verse', () => {
describe('single verse', () => {
it('first generic verse', () => {
const 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.`,
]
expect(recite(10, 1)).toEqual(expected)
})

xit('last generic verse', () => {
const 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.`,
]
expect(recite(3, 1)).toEqual(expected)
})

xit('verse with 2 bottles', () => {
const 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.`,
]
expect(recite(2, 1)).toEqual(expected)
})

xit('verse with 1 bottle', () => {
const 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.`,
]
expect(recite(1, 1)).toEqual(expected)
})
})
})

describe('lyrics', () => {
describe('multiple verses', () => {
xit('first two verses', () => {
const 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.`,
]
expect(recite(10, 2)).toEqual(expected)
})

xit('last three verses', () => {
const 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.`,
]
expect(recite(3, 3)).toEqual(expected)
})

xit('all verses', () => {
const 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.`,
]
expect(recite(10, 10)).toEqual(expected)
})
})
})
})
4 changes: 4 additions & 0 deletions exercises/practice/bottle-song/bottle-song.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export const recite = (initialBottleCount: unknown, takeDownCount: unknown): unknown => {
throw new Error('Remove this statement and implement this function')
}
26 changes: 26 additions & 0 deletions exercises/practice/bottle-song/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @ts-check

import tsEslint from 'typescript-eslint'
import config from '@exercism/eslint-config-typescript'
import maintainersConfig from '@exercism/eslint-config-typescript/maintainers.mjs'

export default [
...tsEslint.config(...config, {
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
extends: maintainersConfig,
}),
{
ignores: [
// # Protected or generated
'.git/**/*',
'.vscode/**/*',

//# When using npm
'node_modules/**/*',

// # Configuration files
'babel.config.cjs',
'jest.config.cjs',
],
},
]
22 changes: 22 additions & 0 deletions exercises/practice/bottle-song/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
verbose: true,
projects: ['<rootDir>'],
testMatch: [
'**/__tests__/**/*.[jt]s?(x)',
'**/test/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test).[jt]s?(x)',
],
testPathIgnorePatterns: [
'/(?:production_)?node_modules/',
'.d.ts$',
'<rootDir>/test/fixtures',
'<rootDir>/test/helpers',
'__mocks__',
],
transform: {
'^.+\\.[jt]sx?$': 'babel-jest',
},
moduleNameMapper: {
'^(\\.\\/.+)\\.js$': '$1',
},
}
Loading