Skip to content

Commit

Permalink
Implement FizzBuzz using match
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-j-m committed Sep 23, 2019
1 parent 702bec5 commit c50d976
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions crates/fizzbuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ ruby! {
def generate(bound: i32) -> Vec<String> {
let mut results = Vec::new();
for x in 1..(bound+1) {
if x % 15 == 0 {
results.push("FizzBuzz".to_string())
}
else if x % 3 == 0 {
results.push("Fizz".to_string())
}
else if x % 5 == 0 {
results.push("Buzz".to_string())
}
else {
results.push(x.to_string())
}
results.push(match(x % 3, x % 5) {
(0, 0) => "FizzBuzz".to_string(),
(0, _) => "Fizz".to_string(),
(_, 0) => "Buzz".to_string(),
(_, _) => x.to_string(),
})
}
results
}
Expand Down

0 comments on commit c50d976

Please sign in to comment.