write one-liner fizzbuzz in Rust.
- User
write one-liner fizzbuzz in Rust.
Assistant
Here's a one-liner in Rust that prints "FizzBuzz" up to a given number:
rustfn fizzbuzz(n: i32) { let mut num = 1; while num <= n { if num % 3 == 0 && num % 5 == 0 { println!("FizzBuzz"); } else if num % 3 == 0 { println!("Fizz"); } else if num % 5 == 0 { println!("Buzz"); } else { println!("{}", num); } num += 1; } }You can use this function like this:
codefizzbuzz(15);This will print numbers from 1 to 15, with "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for multiples of both.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.