Last active
May 9, 2016 08:26
-
-
Save zalom/02ad2fc51347ed6b0a91303e93579acf to your computer and use it in GitHub Desktop.
Coding Test - Fizz Buzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fizz-Buzz Ruby | |
# FIND DESCRIPTION BELOW THE CODE | |
puts "Enter a number (integer): " | |
n = gets.chomp.to_i | |
i = 1 | |
n.times do | |
if i%3 == 0 || i%5 ==0 | |
if i%3 == 0 && i%5 == 0 | |
puts "FizzBuzz" | |
elsif i%3 == 0 | |
puts "Fizz" | |
elsif i%5 == 0 | |
puts "Buzz" | |
end | |
else | |
puts i | |
end | |
i = i+1 | |
end | |
# DESCRIPTION | |
# Write a program to print the numbers from 1 to N, each on a new line, 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”. | |
# Input: | |
# * Single integer N. | |
# Output: | |
# * N lines with one integer or string per line as described above. | |
# Constraints: | |
# 0 < N < 10 <sup>7</sup> | |
# Sample Input #1: | |
# > 15 | |
# Sample Output #1: | |
# > 1 | |
# > 2 | |
# > Fizz | |
# > 4 | |
# > Buzz | |
# > Fizz | |
# > 7 | |
# > 8 | |
# > Fizz | |
# > Buzz | |
# > 11 | |
# > Fizz | |
# > 13 | |
# > 14 | |
# > FizzBuzz | |
# Explanation: | |
# * Position 3, 6, 9, 12 have the word "Fizz" because they are multiples of 3. | |
# * Positions 5 and 10 have the word "Buzz" because they are multiples of 5. | |
# * Position 15 has the word FizzBuzz because it is a multiple of both 3 and 5. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment