Created
September 25, 2013 22:55
-
-
Save manleyhimself/6707349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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