Sha256: 94e8631f9fd067f16d8c2152e2ba9e257068e92a977d389cfaab95e10d6877b6

Contents?: true

Size: 998 Bytes

Versions: 171

Compression:

Stored size: 998 Bytes

Contents

pub fn verse(n: i32) -> String {
    match n {
        0 => "No more bottles of beer on the wall, no more bottles of beer.\n\
              Go to the store and buy some more, 99 bottles of beer on the wall.\n".to_string(),
        1 => "1 bottle of beer on the wall, 1 bottle of beer.\n\
              Take it down and pass it around, no more bottles of beer on the wall.\n".to_string(),
        2 => "2 bottles of beer on the wall, 2 bottles of beer.\n\
              Take one down and pass it around, 1 bottle of beer on the wall.\n".to_string(),
        n if n > 2 && n <= 99 =>
            format!(
                "{n} bottles of beer on the wall, {n} bottles of beer.\n\
                 Take one down and pass it around, {n_minus_1} bottles of beer on the wall.\n",
                n=n,
                n_minus_1=n - 1),
        _ =>
            panic!(),
    }
}

pub fn sing(start: i32, end: i32) -> String {
    (end .. start + 1).rev().map(|n| verse(n)).collect::<Vec<_>>().join("\n")
}

Version data entries

171 entries across 171 versions & 1 rubygems

Version Path
trackler-2.2.1.37 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.36 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.35 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.34 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.33 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.32 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.31 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.30 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.29 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.28 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.27 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.26 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.25 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.24 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.23 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.22 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.21 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.20 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.19 tracks/rust/exercises/beer-song/example.rs
trackler-2.2.1.18 tracks/rust/exercises/beer-song/example.rs