Created
November 23, 2015 07:24
-
-
Save c000/15a405b41c0ee8bf40b5 to your computer and use it in GitHub Desktop.
This file contains 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
fn fizz(n: i32) -> String { | |
match n { | |
n if n % 15 == 0 => format!("{}", "FizzBuzz"), | |
n if n % 3 == 0 => format!("{}", "Fizz"), | |
n if n % 5 == 0 => format!("{}", "Buzz"), | |
n => format!("{}", n), | |
} | |
} | |
fn fizz2(n: i32) -> String { | |
let mut buf = String::new(); | |
if n % 3 == 0 { | |
buf.push_str("Fizz") | |
} | |
if n % 5 == 0 { | |
buf.push_str("Buzz") | |
} | |
if buf.is_empty() { | |
buf.push_str(&n.to_string()) | |
} | |
buf | |
} | |
fn main() { | |
let end = std::env::args().nth(1).unwrap().parse().unwrap(); | |
for i in 0..end { | |
println!("{:10}|{:10}", fizz(i), fizz2(i)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment