diff --git a/solutions/rust/bottle-song/2/Cargo.toml b/solutions/rust/bottle-song/2/Cargo.toml new file mode 100644 index 0000000..a133c66 --- /dev/null +++ b/solutions/rust/bottle-song/2/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "bottle_song" +version = "0.1.0" +edition = "2024" + +# Not all libraries from crates.io are available in Exercism's test runner. +# The full list of available libraries is here: +# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml +[dependencies] diff --git a/solutions/rust/bottle-song/2/src/lib.rs b/solutions/rust/bottle-song/2/src/lib.rs new file mode 100644 index 0000000..fc6c91f --- /dev/null +++ b/solutions/rust/bottle-song/2/src/lib.rs @@ -0,0 +1,74 @@ +pub fn recite(start_bottles: u32, take_down: u32) -> String { + LYRICS.iter().skip((10 - start_bottles) as usize).take(take_down as usize).map(|x| x.to_string()).collect() +} + +const LYRICS: [&str; 10] = [ +"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. + +"];