Monday, February 4, 2008

Programming Puzzlers

So, I'm going to try and do this as a weekly thing. Please do not post your answers in the comments, if you're really bugging for an answer, feel free to e-mail me.

So, without further adieu, the weekly column:

Programming Puzzlers!



There is a a well known interview question known as the 'FizzBuzz' Question. It asks for you to write a program with the following requirements:

Print 1 to 100 on separate lines to the console, unless
1. The number is divisible by 3, then print "Fizz"
2. The number is divisible by 5, then print "Buzz"
3. The number is divisible by both 3 and 5, then print "FizzBuzz"

This is a very simple question that, apparently, a lot of interviewees fail (find a new career, smart guy). My question is not can you program it; my question is, can you program it only using one line?

And, no, removing the whitespace from your program does not count as one line! Keep in mind this is just a puzzle, something to think about, a way to figure out how to abuse language features. If you ever think coding the way I'm asking you to right now is a good idea, punch yourself in a jaw, twice.