Created
February 5, 2012 06:52
-
-
Save sassy/1743591 to your computer and use it in GitHub Desktop.
rustでfizzbuzz
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
| use std; | |
| fn is_fizzbuzz(x:int) -> bool { x % 15 == 0} | |
| fn is_fizz(x:int) -> bool { x % 3 == 0} | |
| fn is_buzz(x:int) -> bool { x % 5 == 0} | |
| fn fizzbuzz(n:int) -> str { | |
| ret | |
| if is_fizzbuzz(n) { "fizzbuzz"} | |
| else if is_fizz(n) { "fizz" } | |
| else if is_buzz(n) {"buzz" } | |
| else { int::str(n) }; | |
| } | |
| fn main() { | |
| let x: int = 0; | |
| while true { | |
| if x >= 30 { break;} | |
| x += 1; | |
| std::io::println(fizzbuzz(x)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment