Skip to content

Instantly share code, notes, and snippets.

@andersr
Created October 11, 2013 15:10
Show Gist options
  • Save andersr/6936344 to your computer and use it in GitHub Desktop.
Save andersr/6936344 to your computer and use it in GitHub Desktop.
fizz, buzz, fizz_buzz, no_buzz = [], [], [], []
(1..50).each do |n|
if (n % 3 == 0) && (n % 5 == 0)
fizz_buzz.push(n)
elsif n % 3 == 0
fizz.push(n)
elsif n % 5 == 0
buzz.push(n)
else
no_buzz.push(n)
end
end
def puts_buzzes(name,number)
print "#{name}:"
number.each do |n|
print "#{n}, "
end
puts
end
puts_buzzes("FizzBuzzes",fizz_buzz)
puts_buzzes("Fizzes",fizz)
puts_buzzes("Buzzes",buzz)
puts_buzzes("Neither",no_buzz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment