Skip to content

Commit

Permalink
Add bottle-song exercise (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Oct 21, 2024
1 parent 25f2e45 commit 7b28382
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 12 deletions.
33 changes: 21 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,10 @@
"slug": "beer-song",
"name": "Beer Song",
"uuid": "0ea0d92f-5510-4ba9-b419-3f5ad029b74f",
"practices": [
"ranges",
"string-formatting"
],
"prerequisites": [
"lists",
"numbers",
"ranges",
"string-formatting",
"strings"
],
"difficulty": 3
"practices": [],
"prerequisites": [],
"difficulty": 3,
"status": "deprecated"
},
{
"slug": "kindergarten-garden",
Expand Down Expand Up @@ -2182,6 +2174,23 @@
"numbers"
],
"difficulty": 5
},
{
"slug": "bottle-song",
"name": "Bottle Song",
"uuid": "05f6895a-b770-4a07-8db8-3787adf5fdf9",
"practices": [
"ranges",
"string-formatting"
],
"prerequisites": [
"lists",
"numbers",
"ranges",
"string-formatting",
"strings"
],
"difficulty": 3
}
],
"foregone": [
Expand Down
12 changes: 12 additions & 0 deletions exercises/practice/bottle-song/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fantomas-tool": {
"version": "4.7.9",
"commands": [
"fantomas"
]
}
}
}
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.
```
29 changes: 29 additions & 0 deletions exercises/practice/bottle-song/.meta/Example.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module BottleSong

let private counts =
[| "no"
"one"
"two"
"three"
"four"
"five"
"six"
"seven"
"eight"
"nine"
"ten" |]

let private capitalize (s: string) = $"{System.Char.ToUpper(s[0])}{s[1..]}"

let private bottles n = if n = 1 then "bottle" else "bottles"

let private verse bottleCount =
[ $"{counts[bottleCount] |> capitalize} green {bottles bottleCount} hanging on the wall,"
$"{counts[bottleCount] |> capitalize} green {bottles bottleCount} hanging on the wall,"
$"And if one green {bottles 1} should accidentally fall,"
$"There'll be {counts[bottleCount - 1]} green {bottles (bottleCount - 1)} hanging on the wall." ]

let recite startBottles takeDown =
[ startBottles .. -1 .. (startBottles - takeDown + 1) ]
|> List.map verse
|> List.reduce (fun x y -> x @ "" :: y)
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": [
"erikschierboom"
],
"files": {
"solution": [
"BottleSong.fs"
],
"test": [
"BottleSongTests.fs"
],
"example": [
".meta/Example.fs"
]
},
"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"
}
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"
4 changes: 4 additions & 0 deletions exercises/practice/bottle-song/BottleSong.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module BottleSong

let recite startBottles takeDown =
failwith "Please implement the 'recite' function"
22 changes: 22 additions & 0 deletions exercises/practice/bottle-song/BottleSong.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<Compile Include="BottleSong.fs" />
<Compile Include="BottleSongTests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Exercism.Tests" Version="0.1.0-beta1" />
<PackageReference Include="FsUnit.xUnit" Version="4.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
136 changes: 136 additions & 0 deletions exercises/practice/bottle-song/BottleSongTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
module BottleSongTests

open FsUnit.Xunit
open Xunit

open BottleSong

[<Fact>]
let ``First generic verse`` () =
recite 10 1
|> should
equal
[ "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." ]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Last generic verse`` () =
recite 3 1
|> should
equal
[ "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." ]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Verse with 2 bottles`` () =
recite 2 1
|> should
equal
[ "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." ]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Verse with 1 bottle`` () =
recite 1 1
|> should
equal
[ "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." ]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``First two verses`` () =
recite 10 2
|> should
equal
[ "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." ]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Last three verses`` () =
recite 3 3
|> should
equal
[ "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." ]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``All verses`` () =
recite 10 10
|> should
equal
[ "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." ]
3 changes: 3 additions & 0 deletions generators/Generators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2044,3 +2044,6 @@ type EliudsEggs() =

type Knapsack() =
inherit ExerciseGenerator()

type BottleSong() =
inherit ExerciseGenerator()

0 comments on commit 7b28382

Please sign in to comment.