

What's the shortest FizzBuzz you can write? What language? - jontsai
http://golf.shinh.org/p.rb?FizzBuzz

======
jontsai
I first heard about FizzBuzz from Hackruiter.com and then I got an email from
RapLeaf ([http://blog.rapleaf.com/dev/2011/09/06/code-golfing-at-
the-o...](http://blog.rapleaf.com/dev/2011/09/06/code-golfing-at-the-office))

It's a very interesting concept to filter out the bad programmers using
something simple like FizzBuzz. What do you guys like to give out as
programming or interview questions? How effective are they?

~~~
par
I believe FizzBuzz was first brought to attention by Jeff Atwood in his Coding
Horror blog [http://www.codinghorror.com/blog/2007/02/fizzbuzz-the-
progra...](http://www.codinghorror.com/blog/2007/02/fizzbuzz-the-programmers-
stairway-to-heaven.html).

When interviewing, we'll generally ask questions about data structures and
class design (design a card game), very basic looping and guards (do
FizzBuzz), iterative vs. recursive programming (implement Fibonacci using
both), and sometimes we will throw some discrete math problems in there too.
These questions, coupled with making a strong effort to really get to know the
candidate (is this someone you want to spend a lot of time with?) can really
help for effective hiring.

------
rorrr
the shortest I could do is 72 characters in PHP. I have no idea how they can
do 56.

    
    
        <? while(++$i<101)echo $i%15?$i%5?$i%3?$i:'Fizz':'Buzz':'FizzBuzz',"\n";

~~~
jontsai
Don't think you can do $i%15, still need to do that check separately. I like
how you can leave out the closing ?>. you can also save 2 spaces by getting
rid of whitespace between statements and symbols .

The comments on the RapLeaf blog post I linked to in this thread has a guy
trying out different Ruby solutions. Very clever!

~~~
rorrr
That code produces correct output. It passed.

PHP does not require a closing ?>

~~~
jontsai
Ohhh. I was thinking about it wrong. Probably obvious to others, but I forgot
about the property that if you have primes p and q, any number n (evenly)
divisible by p that is also divisible by q must be divisible by the product of
p*q.

That shortcut is a result of hyper-optimization and I was thinking more along
the lines of code-reusability (e.g. if the rules of FizzBuzz were changed from
%3 and %5 to %x and %y) =P

