Skip to content

Instantly share code, notes, and snippets.

@manleyhimself
Created September 25, 2013 22:55
Show Gist options
  • Save manleyhimself/6707349 to your computer and use it in GitHub Desktop.
Save manleyhimself/6707349 to your computer and use it in GitHub Desktop.
def fizzbuzz(limit)
fizz_array = []
buzz_array = []
fb_array = []
num = 1
while num <= limit
if (num % 3 == 0) && (num % 5 == 0)
puts "fizzbuzz"
fb_array << num
elsif num % 3 == 0
puts "fizz"
fizz_array << num
elsif num % 5 == 0
puts "buzz"
buzz_array << num
else
puts num
end
num += 1
end
puts "fizzes: #{fizz_array}"
puts "buzzes: #{buzz_array}"
puts "fizzbuzzes: #{fb_array}"
end
fizzbuzz(50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment