You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
497 B
30 lines
497 B
1 year ago
|
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);
|
||
|
}
|
||
|
}
|