Skip to content

Instantly share code, notes, and snippets.

@alexispurslane
Created December 7, 2014 03:38
Show Gist options
  • Save alexispurslane/f0901e7133022863f131 to your computer and use it in GitHub Desktop.
Save alexispurslane/f0901e7133022863f131 to your computer and use it in GitHub Desktop.
Fizzbuzz Functional in rust
/*
* Rust Fizzbuzz functional implementation
*/
fn fb (i: int) -> () {
let mod5 = i % 5 == 0;
let mod3 = i % 3 == 0;
match [mod5, mod3] {
[false, true] => println!("Fizz"),
[true, false] => println!("Buzz"),
[false, false] => println!("{}", i),
[true, true] => println!("FizzBuzz")
}
}
fn fizzbuzz (up_to: int) -> () {
fb(up_to);
if up_to > 0 { fizzbuzz(up_to - 1) }
}
fn main () {
fizzbuzz(100)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment