Skip to content

Commit

Permalink
Replace beer song with bottle song (#724)
Browse files Browse the repository at this point in the history
Replace beer song with bottle song
  • Loading branch information
IsaacG authored Jan 19, 2025
1 parent ed78d83 commit 75cce68
Show file tree
Hide file tree
Showing 9 changed files with 993 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,19 @@
"practices": [],
"prerequisites": [],
"difficulty": 3,
"topics": [
"control_flow_loops",
"text_formatting"
],
"status": "deprecated"
},
{
"slug": "bottle-song",
"name": "Bottle Song",
"uuid": "97ab9f1e-d30f-451d-a3d1-5b926b7df26b",
"practices": [],
"prerequisites": [],
"difficulty": 3,
"topics": [
"control_flow_loops",
"text_formatting"
Expand Down
3 changes: 3 additions & 0 deletions exercises/practice/beer-song/.deprecated
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**NOTE: This exercise has been deprecated**
Your track should implement "bottle-song" instead.
https://github.com/exercism/problem-specifications/issues/2066
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.
```
19 changes: 19 additions & 0 deletions exercises/practice/bottle-song/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"IsaacG"
],
"files": {
"solution": [
"bottle_song.sh"
],
"test": [
"bottle_song.bats"
],
"example": [
".meta/example.sh"
]
},
"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"
}
36 changes: 36 additions & 0 deletions exercises/practice/bottle-song/.meta/example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

declare -a nums=(no one two three four five six seven eight nine ten)

main() {
if (( $# != 2 )); then
echo "2 arguments expected" >&2
exit 1
elif (( $1 < $2 )); then
echo "cannot generate more verses than bottles" >&2
exit 1
fi
for (( i = 0; i < $2; i++ )); do
verse $(( $1 - i ))
done
}

verse() {
local cur=$(bottles "$1")
local next=$(bottles "$(( $1 - 1 ))")
printf "%s hanging on the wall,\n" "${cur^}"
printf "%s hanging on the wall,\n" "${cur^}"
printf "And if one green bottle should accidentally fall,\n"
printf "There'll be %s hanging on the wall.\n" "${next}"
printf "\n"
}

bottles() {
if (( $1 == 1 )); then
echo "${nums[$1]} green bottle"
else
echo "${nums[$1]} green bottles"
fi
}

main "$@"
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"
Loading

0 comments on commit 75cce68

Please sign in to comment.