Ah! algunas variantes. Creo que mi forma es medio ingenua, viene a ser algo asi 
como el bubble-sort de los FizzBuzz 

1.upto(100) do |n|
    div_by_3= n % 3 == 0 ? true : false
    div_by_5= n % 5 == 0 ? true : false
    
    case
    when (div_by_3 and div_by_5): puts "FizBuzz"
    when div_by_3: puts "Fizz"
    when div_by_5: puts "Buzz"
    else                 puts n.to_s
    end
end


Aureliano Calvo <[EMAIL PROTECTED]> escribió: 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


       
---------------------------------

¿Querés asombrarte?
Conocé el nuevo Correo Yahoo! beta
 que incluye muchas herramientas que harán tu vida más sencilla.
_______________________________________________
ruby mailing list
[email protected]
http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar

Responder a