-
-
Save ejholmes/4362351 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
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) } | |
); | |
} | |
} |
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
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