Skip to main content
Code Review

Return to Question

Tweeted twitter.com/StackCodeReview/status/1507054670577127432
Fixed syntax for the if statment.
Source Link
user
  • 265
  • 1
  • 3
  • 9

Can you write an a simpler Rust fizzbuzz program than I have? Use my output or the spec:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

to write your program. I want to see if it's possible to write an even simpler program.

fn main() {
 for i in 1..102 {
 match i {
 i if (i % 3 == 0) && (i % 515 == 0) => { println!("{:?}", "FizzBuzz") },
 i if (i % 3 == 0) => { println!("{:?}", "Fizz") },
 i if (i % 5 == 0) => { println!("{:?}", "Buzz") },
 _ => { println!("{:?}", i) },
 }
 }
}

Can you write an a simpler Rust fizzbuzz program than I have? Use my output or the spec:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

to write your program. I want to see if it's possible to write an even simpler program.

fn main() {
 for i in 1..102 {
 match i {
 i if (i % 3 == 0) && (i % 5 == 0) => { println!("{:?}", "FizzBuzz") },
 i if (i % 3 == 0) => { println!("{:?}", "Fizz") },
 i if (i % 5 == 0) => { println!("{:?}", "Buzz") },
 _ => { println!("{:?}", i) },
 }
 }
}

Can you write an a simpler Rust fizzbuzz program than I have? Use my output or the spec:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

to write your program. I want to see if it's possible to write an even simpler program.

fn main() {
 for i in 1..102 {
 match i {
 i if (i % 15 == 0) => { println!("{:?}", "FizzBuzz") },
 i if (i % 3 == 0) => { println!("{:?}", "Fizz") },
 i if (i % 5 == 0) => { println!("{:?}", "Buzz") },
 _ => { println!("{:?}", i) },
 }
 }
}
added 3 characters in body
Source Link
Shepmaster
  • 8.8k
  • 27
  • 28

Can you write evenan a simpler Rust fizzbuzz program in rustthan I have? Use my output or the spec:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

to write your program. I just want to see if it's possible to dowrite an even simpler program.

fn main() {
 for i in 1..102 {
 match i {
 i if (i % 3 == 0) && (i % 5 == 0) => { println!("{:?}", "FizzBuzz") },
 i if (i % 3 == 0) => { println!("{:?}", "Fizz") },
 i if (i % 5 == 0) => { println!("{:?}", "Buzz") },
 _ => { println!("{:?}", i) },
 }
 }
}

Can you write even simpler fizzbuzz program in rust? Use my output or the spec:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

to write your program. I just want to see if it's possible to do an even simpler program.

fn main() {
 for i in 1..102 {
 match i {
 i if (i % 3 == 0) && (i % 5 == 0) => { println!("{:?}", "FizzBuzz") },
 i if (i % 3 == 0) => { println!("{:?}", "Fizz") },
 i if (i % 5 == 0) => { println!("{:?}", "Buzz") },
 _ => { println!("{:?}", i) },
 }
 }
}

Can you write an a simpler Rust fizzbuzz program than I have? Use my output or the spec:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

to write your program. I want to see if it's possible to write an even simpler program.

fn main() {
 for i in 1..102 {
 match i {
 i if (i % 3 == 0) && (i % 5 == 0) => { println!("{:?}", "FizzBuzz") },
 i if (i % 3 == 0) => { println!("{:?}", "Fizz") },
 i if (i % 5 == 0) => { println!("{:?}", "Buzz") },
 _ => { println!("{:?}", i) },
 }
 }
}
Source Link
user
  • 265
  • 1
  • 3
  • 9

Simplest way to write "FizzBuzz" in Rust

Can you write even simpler fizzbuzz program in rust? Use my output or the spec:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

to write your program. I just want to see if it's possible to do an even simpler program.

fn main() {
 for i in 1..102 {
 match i {
 i if (i % 3 == 0) && (i % 5 == 0) => { println!("{:?}", "FizzBuzz") },
 i if (i % 3 == 0) => { println!("{:?}", "Fizz") },
 i if (i % 5 == 0) => { println!("{:?}", "Buzz") },
 _ => { println!("{:?}", i) },
 }
 }
}
lang-rust

AltStyle によって変換されたページ (->オリジナル) /