Skip to content

Instantly share code, notes, and snippets.

@madelinecr
Last active August 29, 2015 14:02
Show Gist options
  • Save madelinecr/5b977993b4ac48053d40 to your computer and use it in GitHub Desktop.
Save madelinecr/5b977993b4ac48053d40 to your computer and use it in GitHub Desktop.
Fizzbuzz in Rust
fn three_divides(num: int) -> bool {
num % 3 == 0
}
fn five_divides(num: int) -> bool {
num % 5 == 0
}
fn fifteen_divides(num: int) -> bool {
num % 15 == 0
}
fn main() {
for num in range(1, 101) {
println(
if fifteen_divides(num) { ~"FizzBuzz" }
else if three_divides(num) { ~"Fizz" }
else if five_divides(num) { ~"Buzz" }
else { num.to_str() }
);
}
}
#[test]
fn test_three_divides_three() {
assert!(three_divides(3));
}
#[test]
fn test_five_divides_five() {
assert!(five_divides(5));
}
#[test]
fn test_fifteen_divides_fifteen() {
assert!(fifteen_divides(15));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment