[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] FizzBuzz (#126

Ivo Dancet

6/4/2007 7:31:00 PM

Some of my solutions:

#### The one I like:

1.upto(100) do |i|
a, b = i%3, i%5

print "fizz" if a==0
print "buzz" if b==0
print i if a!=0 && b!=0
puts
end

#### The first one, 4 mins, but not something I would leave on a page

100.times do |i|
j = i + 1
if j%15 == 0
puts "fizzbuzz"
next
end
if j%3 == 0
puts "fizz"
next
end
if j%5 == 0
puts "buzz"
next
end
puts j
end

# hmmm, that wasn't so good :-)

#### My one liner (and I spend quite some time to shorten it from 76
to 70 chars, damn, but then again, I never tried to write as-short-as-
possible-one-liners before)

1.upto(100){|i|a=(i%3==0?"fizz":"")+(i%5==0?"buzz":"");puts a[1]?a:i}