Skip to content
Merged
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
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@
"prerequisites": [],
"difficulty": 3
},
{
"slug": "bottle-song",
"name": "Bottle Song",
"uuid": "b1d58dbf-127f-4997-a1d8-09d0c5a16c8f",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "clock",
"name": "Clock",
Expand Down
2 changes: 1 addition & 1 deletion docs/ABOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ For those familiar with Lua, the transition is often smooth, as MoonScript's syn
[lua]: https://exercism.org/tracks/lua/about
[moon]: https://moonscript.org
[github]: https://github.com/leafo/moonscript
[discord]: https://discord.gg/invite/Y75ZXrD
[discord]: https://discord.com/invite/Y75ZXrD
5 changes: 5 additions & 0 deletions exercises/practice/bottle-song/.busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
default = {
ROOT = { '.' }
}
}
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": [
"glennj"
],
"files": {
"solution": [
"bottle_song.moon"
],
"test": [
"bottle_song_spec.moon"
],
"example": [
".meta/example.moon"
]
},
"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"
}
17 changes: 17 additions & 0 deletions exercises/practice/bottle-song/.meta/example.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
nums = {[0]: "No", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"}

bottles = (n) -> "#{nums[n]} green bottle#{n == 1 and "" or "s"}"

verse = (v) ->
lines = {
"#{bottles v} hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be #{string.lower bottles v - 1} hanging on the wall."
}
table.insert lines, 1, lines[1]
table.concat lines, '\n'

{
recite: (first, count) ->
table.concat [verse(v) for v = first, first - count + 1, -1], '\n\n'
}
18 changes: 18 additions & 0 deletions exercises/practice/bottle-song/.meta/generator.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import recite from require <%- h.quote(slug.snake) %>

describe <%- h.quote(slug.kebab .. ':') %>, ->
<% for i, g1 in ipairs(data.cases) do -%>
<% for j, g2 in ipairs(g1.cases) do -%>
describe <%- h.quote(g2.description) %>, ->
<% for k, case in ipairs(g2.cases) do -%>
<%= test_cmd(i == 1 and j == 1 and k == 1) %> <%- h.quote(case.description) %>, ->
<% if not case.expected.error then -%>
expected = [[
<%- table.concat(case.expected, '\n') %>]]
result = <%= case.property %> <%= case.input.startBottles %>, <%= case.input.takeDown %>
assert.are.same expected, result
<% end -%>

<% end -%>
<% end -%>
<% end -%>
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/bottle_song.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
recite: (startVerse, numToTake) ->
error 'Implement me'
}
128 changes: 128 additions & 0 deletions exercises/practice/bottle-song/bottle_song_spec.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import recite from require 'bottle_song'

describe 'bottle-song:', ->
describe 'single verse', ->
it 'first generic verse', ->
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.]]
result = recite 10, 1
assert.are.same expected, result

pending 'last generic verse', ->
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.]]
result = recite 3, 1
assert.are.same expected, result

pending 'verse with 2 bottles', ->
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.]]
result = recite 2, 1
assert.are.same expected, result

pending 'verse with 1 bottle', ->
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.]]
result = recite 1, 1
assert.are.same expected, result

describe 'multiple verses', ->
pending 'first two verses', ->
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.]]
result = recite 10, 2
assert.are.same expected, result

pending 'last three verses', ->
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.]]
result = recite 3, 3
assert.are.same expected, result

pending 'all verses', ->
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.]]
result = recite 10, 10
assert.are.same expected, result

Loading