On 5/11/07, Damian Janowski <[EMAIL PROTECTED]> wrote: > On 5/11/07, Emmanuel Oga <[EMAIL PROTECTED]> wrote: > > Escriban un programa que haga lo siguiente: > > > > "Write a program that prints the numbers from 1 to 100. But for multiples > > of three print "Fizz" instead of the number and for the multiples of five > > print "Buzz". For numbers which are multiples of both three and five print > > "FizzBuzz"." > > > > Lo tienen? no sean vagos.... jajaja haganlo!!!! > > Yo me dediqué 2 minutos y me salió esto :-S > > (1..100).each do |n| > print((s = '') << (n % 3 == 0 ? 'Fizz' : '') << (n % 5 == 0 ? 'Buzz' > : '') << (s.empty? ? n.to_s : '') << "\n") > end
Muy buena, Damián. Golfeando: for n in 1..100; print((s = '') << (n % 3 == 0 ? 'Fizz' : '') + (n % 5 == 0 ? 'Buzz' : '') << (s.any? ? '' : n.to_s) << "\n") end -- Michel _______________________________________________ ruby mailing list [email protected] http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar
