Skip to content

Instantly share code, notes, and snippets.

@ggamel
Created August 26, 2012 15:03
Show Gist options
  • Save ggamel/3480843 to your computer and use it in GitHub Desktop.
Save ggamel/3480843 to your computer and use it in GitHub Desktop.
fizzbuzz
# The most elegant solution for fizzbuzz as taken from http://www.rubyquiz.com/quiz126.html
# This solution is human-readable, easily explainable, and (excluding the ?: ternary operator taken from C) is a good example of Ruby code clarity.
(1..100).each{|i|
x = ''
x += 'Fizz' if i%3==0
x += 'Buzz' if i%5==0
puts(x.empty? ? i : x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment