FizzBuzz in ruby in one line

Some days back I came accross this blog which says about writing the classic fizzbuzz program in one line using Haskell. So that inspired me about writing a single line FizzBuzz program in Ruby. So here you go. This is the code that I came out with.

puts (1..100).map{|i|i%3*i%5==0?(i%3==0?"Fizz":"")+(i%5==0?"Buzz":""):i.to_s}.join(",")

Do let me know if you can come out with something even smaller


Comments

Anonymous said…
1.upto(100).map{|i|s="#{i}:";i%3==0&&s+='fizz';i%5==0&&s+='buzz';puts s}
Tiklu Ganguly said…
Just tried running your code in codepad got error. you can check that out at

http://codepad.org/dUSrGUY3

Popular posts from this blog

Configure Netbeans For Android development

Configuring CI pipeline in Jenkins for PHP projects

Configure Netbeans for Apache TomEE and OpenJPA