FizzBuzz in Rust
The classic screening exercise, written with match rather than if.
fn fizzbuzz(n: u32) {
for i in 1..=n {
match (i % 3, i % 5) {
(0, 0) => println!("FizzBuzz"),
(0, _) => println!("Fizz"),
(_, 0) => println!("Buzz"),
_ => println!("{}", i),
}
}
}
Keywords and builtins used here
fizzbuzzfnforinmatchu32
The run, in numbers
- Lines
- 10
- Characters to type
- 179
- Tokens
- 83
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 59 seconds.
Step 8 of 8 in Control flow, step 18 of 39 in Language basics.