From: Jeremy McAnally Date: 2007-03-03T01:34:06+09:00 Subject: Re: Smallest FizzBuzz program 1.upto(100){|i|p"FizzBuzz#{i}"[i%3<1?0:i%5<1?4:8,i%15<1?8:4]} Shaves off 3 bytes. :) On 3/2/07, Brian Adkins wrote: > This is really bugging me. Someone posted a golf challenge to write a > smallest FizzBuzz program here: > > http://golf.shinh.org/p.rb?FizzBuzz (although the site was down when I > checked it a few minutes ago) > > Basically, the challenge is to write the smallest Ruby program that will > print the numbers from 1 to 100 except: > * substitute Fizz for numbers that are multiples of 3 > * substitute Buzz for numbers that are multiples of 5 > * substitute FizzBuzz for numbers that are multiples of both 3 and 5 > > Also see: http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html > > The winning entry is at 56 bytes and I can't get below 65 bytes with the > following: > > 1.upto(100){|i|puts"FizzBuzz#{i}"[i%3<1?0:i%5<1?4:8,i%15<1?8:4]} > > I think if the substring indices could be computed mathematically > instead of logically, it might work, but it's possible an entirely new > approach is necessary. > > It works correctly, so to see acceptable output, just run it. > > 1 > 2 > Fizz > 4 > Buzz > Fizz > 7 > 8 > Fizz > Buzz > 11 > Fizz > 13 > 14 > FizzBuzz > ... > > Can any Ruby guru out there get it down to 56 bytes? > > Brian > > -- http://www.jeremymcanally.com/ My free Ruby e-book: http://www.humblelittlerubybook.com/book/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.com/