Skip to content

Instantly share code, notes, and snippets.

@c000
Created November 23, 2015 07:24
Show Gist options
  • Save c000/15a405b41c0ee8bf40b5 to your computer and use it in GitHub Desktop.
Save c000/15a405b41c0ee8bf40b5 to your computer and use it in GitHub Desktop.
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