Skip to content

Instantly share code, notes, and snippets.

@byronmejia
Last active February 26, 2016 05:00
Show Gist options
  • Save byronmejia/21425a76b2acb90ecd55 to your computer and use it in GitHub Desktop.
Save byronmejia/21425a76b2acb90ecd55 to your computer and use it in GitHub Desktop.
# Write a program that prints the numbers from 1 to 100. 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”.
def fizzbuzz x
fizz = (x % 3) == 0 ? 'fizz' : ''
buzz = (x % 5) == 0 ? 'buzz' : ''
unless "#{fizz}#{buzz}" == ''
puts "#{fizz}#{buzz}"
else
puts x
end
(x < 100) ? (fizzbuzz x+1) : (return 0)
end
fizzbuzz 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment