Skip to content

Instantly share code, notes, and snippets.

@ArtBears
Created May 10, 2013 20:00
Show Gist options
  • Save ArtBears/5556985 to your computer and use it in GitHub Desktop.
Save ArtBears/5556985 to your computer and use it in GitHub Desktop.
My Ruby Version of FizzBuzz
#Fizbuzz project
=begin
Write a program that prints out the numbers 1 to 100 (inclusive).
If the number is divisible by 3, print Fizz instead of the number. If
it's divisible by 5, print Buzz. If it's divisible by both 3 and 5,
print FizzBuzz.
=end
def fizzbuzz
(1..100).each do |x|
if x % 3 == 0 && x % 5 == 0
x = "FizzBuzz"
puts x
elsif x % 3 == 0
x = "Fizz"
puts x
elsif x % 5 == 0
x = "Buzz"
puts x
else
puts x
end
end
end
fizzbuzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment