Created
November 27, 2010 11:53
-
-
Save mxcl/717832 to your computer and use it in GitHub Desktop.
Improve this Fizzbuzz!
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
#!/usr/bin/ruby | |
# The Ruby FizzBuzz with the best concision versus elegance compromise. | |
# Fork if you have better ideas. | |
1.upto 100 do |n| | |
puts [[:fizz][n%3], [:buzz][n%5]].join[/.+/m] || n | |
end |
You can do or
off of empty strings? I'm jealous.
I also like that you can do if statements inside of array constructs.
here is a much sillier possiblity
1.upto(100) { |n| puts Integer(((a=[[:fizz][n%3], [:buzz][n%5]])+[n]).join) rescue puts a.join }
Hah. I like it.
jank, but less chars:
100.times { |n| puts "#{'fizz' if n%3==0}#{'buzz' if n%5==0}#{n if n%3!=0 && n%5!=0}" }
I feel like we need an obfuscated fizzbuzz contest?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might like Python (https://gist.github.com/720888):