Skip to content

Fizz Buzz Test written with rust to learn rust language

Notifications You must be signed in to change notification settings

jprando/rust-fizzbuzz-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FizzBuzz Test

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”.

wikipedia

In this repository

The implementation of the FizzBuzz test in rust language.

fn ShowMe() { the_code }

content of main.rs file

fn main() {
  (1..101u8).map(|num| match(num % 3, num % 5) {
    (0, 0) => "FIZZBUZZ".into(),
    (0, _) => "FIZZ".into(),
    (_, 0) => "BUZZ".into(),
    _ => num.to_string()
    }).for_each(|num| println!("{}", num))
}

Benchmark

❯ hyperfine -m 1000 target/release/fizzbuss-x86_64-linux
Benchmark #1: target/release/fizzbuss-x86_64-linux
  Time (mean ± σ):       1.8 ms ±   0.4 ms    [User: 1.2 ms, System: 0.7 ms]
  Range (min … max):     1.1 ms …   3.0 ms    1000 runs

About

Fizz Buzz Test written with rust to learn rust language

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages