[RUBY] A memorandum of the FizzBuzz problem

The FizzBuzz problem that appeared in yesterday's drill.

As a model answer,

def fizz_buzz
  num = 1
  while num <= 100 do
    if num % 15 == 0
      puts "FizzBuzz"
    elsif num % 3 == 0
      puts "Fizz"
    elsif num % 5 == 0
      puts "Buzz"
      puts num

    num = num + 1


That was the correct answer, When I used rubocop,

def fizz_buzz
  num = 1
  while num <= 100
    if (num % 15).zero?
      puts 'FizzBuzz'
    elsif (num % 3).zero?
      puts 'Fizz'
    elsif (num % 5).zero?
      puts 'Buzz'
      puts num
    num += 1


In the form of Enclose the formula in () and judge "whether or not the value is 0", Another description (accidentally) using the zero? method was made.

As for rubocop, I think it would be nice to have a clean and tidy description as much as possible.

Recommended Posts

A memorandum of the FizzBuzz problem
Explanation of the FizzBuzz problem
Let's solve the FizzBuzz problem!
I tried the FizzBuzz problem
[Java] When writing the source ... A memorandum of understanding ①
A memorandum of the environment variable "JAVA_HOME" path setting procedure
A memorandum of personal phpenv install
Expression used in the fizz_buzz problem
A solution to the problem of blank spaces at the beginning of textarea
Find the difference from a multiple of 10
[Ruby] FizzBuzz problem
[Ruby] FizzBuzz problem
A memorandum to clean up the code Ruby
Make a margin to the left of the TextField
Measure the size of a folder in Java
Set the time of LocalDateTime to a specific time
[Laravel] Command memorandum until the start of the project
[Ruby on Rails] A memorandum of layout templates
A quick look at the Monty Hall problem
[Rails tutorial] A memorandum of "Chapter 11 Account Activation"
Creating a sample program using the problem of a database specialist in DDD Improvement 2
Creating a sample program using the problem of a database specialist in DDD Improvement 1
Count the number of occurrences of a string in Ruby
The world of clara-rules (2)
A memorandum of addiction to Spring Boot2 x Doma2
About the problem of deadlock in parallel processing in gem'sprockets' 4.0
[Beginner's point of view] I tried to solve the FizzBuzz problem "easily" with Ruby!
The story of making a reverse proxy with ProxyServlet
Judgment of the calendar
The world of clara-rules (4)
The world of clara-rules (3)
I read the "Object-Oriented Practical Guide", so a memorandum
I wrote a sequence diagram of the j.u.c.Flow sample
Display the average value of the evaluation as a star
The world of clara-rules (5)
The idea of quicksort
Extract a specific element from the list of objects
Try to solve a restricted FizzBuzz problem in Java
A review note of the Spring Framework Resource interface
I learned about the existence of a gemspec file
A record of studying the Spring Framework from scratch
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
A survey of the Kubernetes native Java framework Quarkus
[Java] The problem that true was returned as a result of comparing Integer with ==
The idea of jQuery
A quick explanation of the five types of static in Java
Check the dependency of a specific maven artifact in Coursier
I took a peek at the contents of Java's HashMap
Determine that the value is a multiple of 〇 in Ruby
Check the operation of two roles with a chat application
Have you ever thought about the definition of "bad design"?
[PostgreSQL] The story that you have to cut the session properly
A memorandum of the FizzBuzz problem
Let's take a look at the screen of Quant Analyzer!
A note about the seed function of Ruby on Rails
I tried JAX-RS and made a note of the procedure
[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
Follow function association memorandum (understand the description of the User model)
[Ruby] How to retrieve the contents of a double hash
Java: The problem of which is faster, stream or loop
Explain the benefits of the State pattern with a movie rating
A program that counts the number of words in a List
A memorandum to reach the itchy place for Java Gold