Skip to content

Commit

Permalink
Merge branch 'main' into add-new-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 authored Nov 9, 2024
2 parents 8e3afbe + 1a6a28c commit d278534
Show file tree
Hide file tree
Showing 17 changed files with 416 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/exercise-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
ruby-version: [3.2, 3.3]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

- name: Set up Ruby
uses: ruby/setup-ruby@52753b7da854d5c07df37391a986c76ab4615999
uses: ruby/setup-ruby@7d3497fd78c07c0d84ebafa58d8dac60cd1f0763
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.3.0
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ GEM
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.0)
rexml (3.3.6)
strscan
rexml (3.3.9)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
Expand Down
14 changes: 14 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,20 @@
],
"difficulty": 6
},
{
"slug": "bottle-song",
"name": "Bottle Song",
"uuid": "fb29b743-0f2d-46fe-8a2a-14973259bb2b",
"practices": [
"strings"
],
"prerequisites": [
"strings",
"numbers",
"loops"
],
"difficulty": 3
},
{
"slug": "beer-song",
"name": "Beer Song",
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.
```
17 changes: 17 additions & 0 deletions exercises/practice/bottle-song/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"authors": ["meatball133"],
"files": {
"solution": [
"bottle_song.rb"
],
"test": [
"bottle_song_test.rb"
],
"example": [
".meta/example.rb"
]
},
"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"
}
18 changes: 18 additions & 0 deletions exercises/practice/bottle-song/.meta/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module BottleSong

TRANSLATE = {
0 => "no", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five",
6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten"
}

def self.recite(start, amount)
((start - amount + 1)..(start)).to_a.reverse.map do |current|
<<~TEXT
#{TRANSLATE[current].capitalize} green #{current == 1 ? "bottle" : "bottles"} hanging on the wall,
#{TRANSLATE[current].capitalize} green #{current == 1 ? "bottle" : "bottles"} hanging on the wall,
And if one green bottle should accidentally fall,
There'll be #{TRANSLATE[current - 1]} green #{current - 1 == 1 ? "bottle" : "bottles"} hanging on the wall.
TEXT
end.join("\n")
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"
7 changes: 7 additions & 0 deletions exercises/practice/bottle-song/bottle_song.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=begin
Write your code for the 'BottleSong' exercise in this file. Make the tests in
`bottle_song_test.rb` pass.
To get started with TDD, see the `README.md` file in your
`ruby/bottle-song` directory.
=end
141 changes: 141 additions & 0 deletions exercises/practice/bottle-song/bottle_song_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
require 'minitest/autorun'
require_relative 'bottle_song'

class BottleSongTest < Minitest::Test
def test_single_verse
# skip
expected = <<~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.
TEXT
assert_equal expected, BottleSong.recite(10, 1)
end

def test_last_generic_verse
skip
expected = <<~TEXT
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.
TEXT
assert_equal expected, BottleSong.recite(3, 1)
end

def test_verse_with_2_bottles
skip
expected = <<~TEXT
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.
TEXT
assert_equal expected, BottleSong.recite(2, 1)
end

def test_verse_with_1_bottle
skip
expected = <<~TEXT
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.
TEXT
assert_equal expected, BottleSong.recite(1, 1)
end

def test_first_two_verses
skip
expected = <<~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.
TEXT
assert_equal expected, BottleSong.recite(10, 2)
end

def test_last_three_verses
skip
expected = <<~TEXT
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.
TEXT
assert_equal expected, BottleSong.recite(3, 3)
end

def test_all_verses
skip
expected = <<~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.
TEXT
assert_equal expected, BottleSong.recite(10, 10)
end
end
3 changes: 2 additions & 1 deletion exercises/practice/palindrome-products/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"Insti",
"kotp",
"markijbema",
"tryantwit"
"tryantwit",
"themetar"
],
"files": {
"solution": [
Expand Down
Loading

0 comments on commit d278534

Please sign in to comment.