Skip to content

Instantly share code, notes, and snippets.

@ejholmes
Forked from steveklabnik/buzz.rs
Last active December 10, 2015 01:48
Show Gist options
  • Save ejholmes/4362351 to your computer and use it in GitHub Desktop.
Save ejholmes/4362351 to your computer and use it in GitHub Desktop.
extern mod std;
fn is_three(num: int) -> bool {
num % 3 == 0
}
#[test]
fn test_is_three() {
assert is_three(1) == false;
assert is_three(3) == true;
}
fn is_five(num: int) -> bool {
num % 5 == 0
}
#[test]
fn test_is_five() {
assert is_five(1) == false;
assert is_five(5) == true;
}
fn is_fifteen(num: int) -> bool {
num % 15 == 0
}
#[test]
fn test_is_fifteen() {
assert is_fifteen(1) == false;
assert is_fifteen(15) == true;
}
fn main() {
for int::range(0, 100) |num| {
io::println(
if is_fifteen(num) { ~"FizzBuzz" }
else if is_three(num) { ~"Fizz" }
else if is_five(num) { ~"Buzz" }
else { int::str(num) }
);
}
}
extern mod std;
fn is_three(num: int) -> bool {
num % 3 == 0
}
#[test]
fn test_is_three() {
assert is_three(1) == false;
assert is_three(3) == true;
}
fn is_five(num: int) -> bool {
num % 5 == 0
}
#[test]
fn test_is_five() {
assert is_five(1) == false;
assert is_five(5) == true;
}
fn is_fifteen(num: int) -> bool {
num % 15 == 0
}
#[test]
fn test_is_fifteen() {
assert is_fifteen(1) == false;
assert is_fifteen(15) == true;
}
fn main() {
for int::range(0, 100) |num| {
let answer =
if is_fifteen(num){
~"FizzBuzz"
}
else if is_three(num) {
~"Fizz"
}
else if is_five(num) {
~"Buzz"
}
else {
int::str(num)
};
io::println(answer)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment