Created
January 31, 2013 18:43
-
-
Save blithe/4685203 to your computer and use it in GitHub Desktop.
FizzBuzz in Ruby
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
def FizzBuzz | |
# for numbers 1 to 100, print Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both | |
(1..100).each do |n| | |
print "#{n} = " | |
if n % 3 == 0 && n % 15 == 0 | |
puts "FizzBuzz" | |
elsif n % 5 == 0 | |
puts "Buzz" | |
elsif n % 3 == 0 | |
puts "Fizz" | |
else | |
# nothing | |
puts "\n" | |
end | |
end | |
puts "\n" | |
end | |
print fizzbuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment