A mi mucho los one-liners no me gustan, así que escribí algo más largo y (IMNSHO) claro. En particular me parece que quedó más legible poniendo los if y unless a la derecha.
#!/usr/bin/env ruby (1..100).each do |n| div_by_3 = ( n % 3 ) == 0 div_by_5 = ( n % 5 ) == 0 print "Fizz" if div_by_3 print "Buzz" if div_by_5 print n unless ( div_by_3 or div_by_5 ) end
"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"."
_______________________________________________ ruby mailing list [email protected] http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar
