Skip to content

Instantly share code, notes, and snippets.

@aulisius
Created February 3, 2016 01:09
Show Gist options
  • Save aulisius/87fde75e03a8e4d14519 to your computer and use it in GitHub Desktop.
Save aulisius/87fde75e03a8e4d14519 to your computer and use it in GitHub Desktop.
FizzBuzz in Rust
fn main() {
(1..100)
.filter(|&x| x % 3 == 0 || x % 5 == 0)
.map(|x| {
let mut str = String::new();
if x % 3 == 0 {
str.push_str("Fizz");
}
if x % 5 == 0 {
str.push_str("Buzz");
}
println!("{} {}", str, x);
x
})
.collect::<Vec<i32>>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment