Skip to content

Instantly share code, notes, and snippets.

@emberlzhang
Created July 5, 2013 20:24
Show Gist options
  • Save emberlzhang/5937010 to your computer and use it in GitHub Desktop.
Save emberlzhang/5937010 to your computer and use it in GitHub Desktop.
FizzBuzz in Ruby: 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.
numbers = Array(1..100)
numbers.each do |num|
if num % 15 == 0
puts "FizzBuzz"
elsif num % 5 == 0
puts "Buzz"
elsif num % 3 == 0
puts "Fizz"
else
puts num
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment