Learn R Programming

mark (version 0.8.2)

fizzbuzz: Fizz Buzz

Description

For when someone asked you to do something you've done before, you can argue that the quickest way to do it is to just take the work someone else did and utilize that. No reason to reinvent the wheel.

Usage

fizzbuzz(n, show_numbers = TRUE)

fizzbuzz_lazy(n)

.fizzbuzz_vector

Value

A character vector of 1, 2, Fizz, 3, Buzz, etc

Format

An object of class character of length 1000000.

Arguments

n

The number of numbers

show_numbers

If TRUE shows no

Details

Multiples of 3 are shown as "Fizz"; multiples of 5 as "Buzz"; multiple of both (i.e., 15) are "FizzBuzz". fizzbuzz_lazy() subsets the .fizzbuzz_vector object, which is a solution with default parameters up to 1e6

Examples

Run this code
fizzbuzz(15)
fizzbuzz(30, show_numbers = FALSE)
cat(fizzbuzz(30), sep = "\n")

# \donttest{
# show them how fast your solution is:
if (package_available("bench")) {
  bench::mark(fizzbuzz(1e5), fizzbuzz_lazy(1e5))
}
# }

Run the code above in your browser using DataLab