Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Created April 12, 2014 16:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fliiiix/10545453 to your computer and use it in GitHub Desktop.
# my solution
(1..100).each do |number|
out = ""
out = number.to_s if number % 3 != 0 && number % 5 != 0
out = "Fizz" if number % 3 == 0
out += "Buzz" if number % 5 == 0
puts out + "\n"
end
# better solution
def fizzbuzz(max):
1.upto(max).each do |n|
line = ''
line << 'Fizz' if n % 3 == 0
line << 'Buzz' if n % 5 == 0
line = n if line.empty?
p line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment