Up through fn methods in RBE

This commit is contained in:
2023-09-30 20:05:41 -04:00
parent b94fb3b31e
commit 9d4f5b661b
3 changed files with 106 additions and 6 deletions
+29
View File
@@ -0,0 +1,29 @@
fn main() {
fizzbuzz_to(100);
}
fn is_divisible_by(lhs: u32, rhs: u32) -> bool {
if rhs == 0 {
return false;
}
lhs % rhs == 0
}
fn fizzbuzz(n: u32) -> () {
if is_divisible_by(n, 15) {
println!("fizzbuzz");
} else if is_divisible_by(n, 3) {
println!("fizz");
} else if is_divisible_by(n, 5) {
println!("buzz");
} else {
println!("{}", n);
}
}
fn fizzbuzz_to(n: u32) {
for n in 1..=n {
fizzbuzz(n);
}
}