Skip to content

Commit 16a072e

Browse files
authored
beer-song: replace with bottle-song (#2021)
1 parent bfa2229 commit 16a072e

File tree

10 files changed

+347
-5
lines changed

10 files changed

+347
-5
lines changed

config.json

+12-5
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,23 @@
324324
"slug": "beer-song",
325325
"name": "Beer Song",
326326
"uuid": "bb42bc3a-139d-4cab-8b3a-2eac2e1b77b6",
327-
"practices": [
328-
"loops",
329-
"strings"
330-
],
327+
"practices": [],
331328
"prerequisites": [],
332329
"difficulty": 1,
333330
"topics": [
334331
"case",
335332
"vectors"
336-
]
333+
],
334+
"status": "deprecated"
335+
},
336+
{
337+
"slug": "bottle-song",
338+
"name": "Bottle Song",
339+
"uuid": "31e8185b-39d8-48c6-88a0-f302e2864f16",
340+
"practices": [],
341+
"prerequisites": [],
342+
"difficulty": 1,
343+
"topics": []
337344
},
338345
{
339346
"slug": "difference-of-squares",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Instructions
2+
3+
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles.
4+
5+
Note that not all verses are identical.
6+
7+
```text
8+
Ten green bottles hanging on the wall,
9+
Ten green bottles hanging on the wall,
10+
And if one green bottle should accidentally fall,
11+
There'll be nine green bottles hanging on the wall.
12+
13+
Nine green bottles hanging on the wall,
14+
Nine green bottles hanging on the wall,
15+
And if one green bottle should accidentally fall,
16+
There'll be eight green bottles hanging on the wall.
17+
18+
Eight green bottles hanging on the wall,
19+
Eight green bottles hanging on the wall,
20+
And if one green bottle should accidentally fall,
21+
There'll be seven green bottles hanging on the wall.
22+
23+
Seven green bottles hanging on the wall,
24+
Seven green bottles hanging on the wall,
25+
And if one green bottle should accidentally fall,
26+
There'll be six green bottles hanging on the wall.
27+
28+
Six green bottles hanging on the wall,
29+
Six green bottles hanging on the wall,
30+
And if one green bottle should accidentally fall,
31+
There'll be five green bottles hanging on the wall.
32+
33+
Five green bottles hanging on the wall,
34+
Five green bottles hanging on the wall,
35+
And if one green bottle should accidentally fall,
36+
There'll be four green bottles hanging on the wall.
37+
38+
Four green bottles hanging on the wall,
39+
Four green bottles hanging on the wall,
40+
And if one green bottle should accidentally fall,
41+
There'll be three green bottles hanging on the wall.
42+
43+
Three green bottles hanging on the wall,
44+
Three green bottles hanging on the wall,
45+
And if one green bottle should accidentally fall,
46+
There'll be two green bottles hanging on the wall.
47+
48+
Two green bottles hanging on the wall,
49+
Two green bottles hanging on the wall,
50+
And if one green bottle should accidentally fall,
51+
There'll be one green bottle hanging on the wall.
52+
53+
One green bottle hanging on the wall,
54+
One green bottle hanging on the wall,
55+
And if one green bottle should accidentally fall,
56+
There'll be no green bottles hanging on the wall.
57+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"authors": [
3+
"ellnix"
4+
],
5+
"files": {
6+
"solution": [
7+
"src/lib.rs",
8+
"Cargo.toml"
9+
],
10+
"test": [
11+
"tests/bottle-song.rs"
12+
],
13+
"example": [
14+
".meta/example.rs"
15+
]
16+
},
17+
"blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.",
18+
"source": "Wikipedia",
19+
"source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles"
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
pub fn recite(start_bottles: u32, take_down: u32) -> String {
2+
(1..=take_down)
3+
.map(|taken_down| {
4+
let b = start_bottles - taken_down;
5+
let b_word = number_to_eng_word(b).to_lowercase();
6+
let b_noun = if b == 1 { "bottle" } else { "bottles" };
7+
let prev_b = b + 1;
8+
let prev_b_word = number_to_eng_word(prev_b);
9+
let prev_b_noun = if prev_b == 1 { "bottle" } else { "bottles" };
10+
[
11+
format!("{prev_b_word} green {prev_b_noun} hanging on the wall"),
12+
format!("{prev_b_word} green {prev_b_noun} hanging on the wall"),
13+
"And if one green bottle should accidentally fall".into(),
14+
format!("There'll be {b_word} green {b_noun} hanging on the wall."),
15+
]
16+
.join(",\n")
17+
})
18+
.collect::<Vec<String>>()
19+
.join("\n\n")
20+
+ "\n"
21+
}
22+
23+
fn number_to_eng_word(digit: u32) -> String {
24+
match digit {
25+
0 => "No",
26+
1 => "One",
27+
2 => "Two",
28+
3 => "Three",
29+
4 => "Four",
30+
5 => "Five",
31+
6 => "Six",
32+
7 => "Seven",
33+
8 => "Eight",
34+
9 => "Nine",
35+
10 => "Ten",
36+
_ => panic!("Didn't bother adding numbers past 10..."),
37+
}
38+
.to_string()
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use bottle_song::*;
2+
3+
{% for group in cases %}
4+
{% for subgroup in group.cases %}
5+
{% for test in subgroup.cases %}
6+
7+
#[test]
8+
#[ignore]
9+
fn {{ test.description | make_ident }}() {
10+
assert_eq!(
11+
recite({{ test.input.startBottles }}, {{ test.input.takeDown }}).trim(),
12+
concat!(
13+
{% for line in test.expected %}
14+
"{{line}}{% if not loop.last %}\n{% endif %}",
15+
{% endfor %}
16+
)
17+
);
18+
}
19+
{% endfor -%}
20+
{% endfor -%}
21+
{% endfor -%}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03]
13+
description = "verse -> single verse -> first generic verse"
14+
15+
[0f0aded3-472a-4c64-b842-18d4f1f5f030]
16+
description = "verse -> single verse -> last generic verse"
17+
18+
[f61f3c97-131f-459e-b40a-7428f3ed99d9]
19+
description = "verse -> single verse -> verse with 2 bottles"
20+
21+
[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0]
22+
description = "verse -> single verse -> verse with 1 bottle"
23+
24+
[a4a28170-83d6-4dc1-bd8b-319b6abb6a80]
25+
description = "lyrics -> multiple verses -> first two verses"
26+
27+
[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db]
28+
description = "lyrics -> multiple verses -> last three verses"
29+
30+
[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28]
31+
description = "lyrics -> multiple verses -> all verses"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
edition = "2021"
3+
name = "bottle_song"
4+
version = "1.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn recite(start_bottles: u32, take_down: u32) -> String {
2+
todo!("Return the bottle song starting at {start_bottles} and taking down {take_down} bottles")
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
use bottle_song::*;
2+
3+
#[test]
4+
fn first_generic_verse() {
5+
assert_eq!(
6+
recite(10, 1).trim(),
7+
concat!(
8+
"Ten green bottles hanging on the wall,\n",
9+
"Ten green bottles hanging on the wall,\n",
10+
"And if one green bottle should accidentally fall,\n",
11+
"There'll be nine green bottles hanging on the wall.",
12+
)
13+
);
14+
}
15+
16+
#[test]
17+
#[ignore]
18+
fn last_generic_verse() {
19+
assert_eq!(
20+
recite(3, 1).trim(),
21+
concat!(
22+
"Three green bottles hanging on the wall,\n",
23+
"Three green bottles hanging on the wall,\n",
24+
"And if one green bottle should accidentally fall,\n",
25+
"There'll be two green bottles hanging on the wall.",
26+
)
27+
);
28+
}
29+
30+
#[test]
31+
#[ignore]
32+
fn verse_with_2_bottles() {
33+
assert_eq!(
34+
recite(2, 1).trim(),
35+
concat!(
36+
"Two green bottles hanging on the wall,\n",
37+
"Two green bottles hanging on the wall,\n",
38+
"And if one green bottle should accidentally fall,\n",
39+
"There'll be one green bottle hanging on the wall.",
40+
)
41+
);
42+
}
43+
44+
#[test]
45+
#[ignore]
46+
fn verse_with_1_bottle() {
47+
assert_eq!(
48+
recite(1, 1).trim(),
49+
concat!(
50+
"One green bottle hanging on the wall,\n",
51+
"One green bottle hanging on the wall,\n",
52+
"And if one green bottle should accidentally fall,\n",
53+
"There'll be no green bottles hanging on the wall.",
54+
)
55+
);
56+
}
57+
58+
#[test]
59+
#[ignore]
60+
fn first_two_verses() {
61+
assert_eq!(
62+
recite(10, 2).trim(),
63+
concat!(
64+
"Ten green bottles hanging on the wall,\n",
65+
"Ten green bottles hanging on the wall,\n",
66+
"And if one green bottle should accidentally fall,\n",
67+
"There'll be nine green bottles hanging on the wall.\n",
68+
"\n",
69+
"Nine green bottles hanging on the wall,\n",
70+
"Nine green bottles hanging on the wall,\n",
71+
"And if one green bottle should accidentally fall,\n",
72+
"There'll be eight green bottles hanging on the wall.",
73+
)
74+
);
75+
}
76+
77+
#[test]
78+
#[ignore]
79+
fn last_three_verses() {
80+
assert_eq!(
81+
recite(3, 3).trim(),
82+
concat!(
83+
"Three green bottles hanging on the wall,\n",
84+
"Three green bottles hanging on the wall,\n",
85+
"And if one green bottle should accidentally fall,\n",
86+
"There'll be two green bottles hanging on the wall.\n",
87+
"\n",
88+
"Two green bottles hanging on the wall,\n",
89+
"Two green bottles hanging on the wall,\n",
90+
"And if one green bottle should accidentally fall,\n",
91+
"There'll be one green bottle hanging on the wall.\n",
92+
"\n",
93+
"One green bottle hanging on the wall,\n",
94+
"One green bottle hanging on the wall,\n",
95+
"And if one green bottle should accidentally fall,\n",
96+
"There'll be no green bottles hanging on the wall.",
97+
)
98+
);
99+
}
100+
101+
#[test]
102+
#[ignore]
103+
fn all_verses() {
104+
assert_eq!(
105+
recite(10, 10).trim(),
106+
concat!(
107+
"Ten green bottles hanging on the wall,\n",
108+
"Ten green bottles hanging on the wall,\n",
109+
"And if one green bottle should accidentally fall,\n",
110+
"There'll be nine green bottles hanging on the wall.\n",
111+
"\n",
112+
"Nine green bottles hanging on the wall,\n",
113+
"Nine green bottles hanging on the wall,\n",
114+
"And if one green bottle should accidentally fall,\n",
115+
"There'll be eight green bottles hanging on the wall.\n",
116+
"\n",
117+
"Eight green bottles hanging on the wall,\n",
118+
"Eight green bottles hanging on the wall,\n",
119+
"And if one green bottle should accidentally fall,\n",
120+
"There'll be seven green bottles hanging on the wall.\n",
121+
"\n",
122+
"Seven green bottles hanging on the wall,\n",
123+
"Seven green bottles hanging on the wall,\n",
124+
"And if one green bottle should accidentally fall,\n",
125+
"There'll be six green bottles hanging on the wall.\n",
126+
"\n",
127+
"Six green bottles hanging on the wall,\n",
128+
"Six green bottles hanging on the wall,\n",
129+
"And if one green bottle should accidentally fall,\n",
130+
"There'll be five green bottles hanging on the wall.\n",
131+
"\n",
132+
"Five green bottles hanging on the wall,\n",
133+
"Five green bottles hanging on the wall,\n",
134+
"And if one green bottle should accidentally fall,\n",
135+
"There'll be four green bottles hanging on the wall.\n",
136+
"\n",
137+
"Four green bottles hanging on the wall,\n",
138+
"Four green bottles hanging on the wall,\n",
139+
"And if one green bottle should accidentally fall,\n",
140+
"There'll be three green bottles hanging on the wall.\n",
141+
"\n",
142+
"Three green bottles hanging on the wall,\n",
143+
"Three green bottles hanging on the wall,\n",
144+
"And if one green bottle should accidentally fall,\n",
145+
"There'll be two green bottles hanging on the wall.\n",
146+
"\n",
147+
"Two green bottles hanging on the wall,\n",
148+
"Two green bottles hanging on the wall,\n",
149+
"And if one green bottle should accidentally fall,\n",
150+
"There'll be one green bottle hanging on the wall.\n",
151+
"\n",
152+
"One green bottle hanging on the wall,\n",
153+
"One green bottle hanging on the wall,\n",
154+
"And if one green bottle should accidentally fall,\n",
155+
"There'll be no green bottles hanging on the wall.",
156+
)
157+
);
158+
}

0 commit comments

Comments
 (0)