Created
October 15, 2016 01:15
-
-
Save seasonedgeek/f02c32304854694bc0691f8fe817ca30 to your computer and use it in GitHub Desktop.
A Simple Implementation of the FizzBuzz problem.
This file contains 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
# A Simple Implementation of the FizzBuzz problem | |
# by Tom Stewart <seasonedgeek> | |
# My curious Ruby experimentation | |
# Identify numbers that are | |
# for multiples of 3 | |
fz = Array.new | |
# for multiples of 5 | |
bz = Array.new | |
# for multiples of 3 & 5 | |
fzbz = Array.new | |
# Requirements | |
# Print numbers from 1 to 100, except | |
# Print “Fizz” for multiples of 3 | |
# Print "Buzz" for multiples of 5 | |
# Print “FizzBuzz” for multiples of both 3 and 5 | |
# | |
(1..100).each do |n| | |
if n % 3 == 0 and n % 5 == 0 | |
fzbz.push(n.to_s) | |
puts "FizzBuzz" | |
elsif n % 3 == 0 | |
fz.push(n.to_s) | |
puts "Fizz" | |
elsif n % 5 == 0 | |
bz.push(n.to_s) | |
puts "Buzz" | |
else | |
puts n.to_s | |
end | |
end | |
# Curiously | |
puts "\n" | |
puts "Numbers identified as multiples of: " | |
puts "\t3 & 5: #{fzbz.join(",")}" | |
puts "\t3: #{fz.join(",")}" | |
puts "\t5: #{bz.join(",")}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment