Skip to content

Instantly share code, notes, and snippets.

@alexyvassili
Created May 25, 2022 02:48
Show Gist options
  • Save alexyvassili/8c6415a0d84ad979fba79a6b314e0535 to your computer and use it in GitHub Desktop.
Save alexyvassili/8c6415a0d84ad979fba79a6b314e0535 to your computer and use it in GitHub Desktop.
Fizzbuzz.rs
use std::vec::Vec;
fn main() {
const COUNT: usize = 100;
let mut result = Vec::with_capacity(COUNT);
for i in 1..=COUNT {
let s = match (i % 3, i % 5) {
(0, 0) => String::from("FizzBuzz"),
(0, _) => String::from("Fizz"),
(_, 0) => String::from("Buzz"),
(_, _) => format!("{}", i),
};
result.push(s);
}
print_result(&result);
}
fn print_result(result: &Vec<String>) {
for r in result {
println!("{}", r)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment