Created
October 29, 2015 17:45
-
-
Save bltavares/2eabe53ccede7cd9ebb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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