Skip to content

Instantly share code, notes, and snippets.

@sassy
Created February 5, 2012 06:52
Show Gist options
  • Save sassy/1743591 to your computer and use it in GitHub Desktop.
Save sassy/1743591 to your computer and use it in GitHub Desktop.
rustでfizzbuzz
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