Created
December 15, 2012 02:39
-
-
Save flakyfilibuster/4290861 to your computer and use it in GitHub Desktop.
FizzBuzz for your viewing pleasure
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
# 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