Created
December 7, 2014 03:38
-
-
Save alexispurslane/f0901e7133022863f131 to your computer and use it in GitHub Desktop.
Fizzbuzz Functional in rust
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
| /* | |
| * 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