Skip to content

Instantly share code, notes, and snippets.

@flakyfilibuster
Created December 15, 2012 02:39
Show Gist options
  • Save flakyfilibuster/4290861 to your computer and use it in GitHub Desktop.
Save flakyfilibuster/4290861 to your computer and use it in GitHub Desktop.
FizzBuzz for your viewing pleasure
# beautifully short and unreadable
def fizzbuzz(n)
(1..n).each {|i| (i%3 == 0) ? ((i%5 == 0) ? (puts "FizzBuzz") : (puts "Fizz")) : ((i%5 == 0) ? (puts "Buzz") : (puts i))}
end
# disgustingly long and readable
def fizzbuzz(n)
(1..n).each do |i|
if i%3==0
if i%5==0
puts "FizzBuzz"
else
puts "Fizz"
end
elsif i%5==0
puts "Buzz"
else
puts i
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment