Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created October 29, 2015 17:45
Show Gist options
  • Save bltavares/2eabe53ccede7cd9ebb5 to your computer and use it in GitHub Desktop.
Save bltavares/2eabe53ccede7cd9ebb5 to your computer and use it in GitHub Desktop.
fn bottles(x : u8) -> String {
match x {
0 => String::from("no more bottles"),
1 => String::from("1 bottle"),
y => format!("{} bottles", y),
}
}
fn phrase(x : u8) -> String {
format!("{current} of beer on the wall
{current} of beer
Take one down, pass it around, {next} of beer on the wall
",
current=bottles(x),
next=bottles(x-1)
)
}
const ZERO : &'static str =
"No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.";
fn main() {
for x in (1..101).rev() {
println!("{}", phrase(x));
}
println!("{}", ZERO)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment