23 Mar 2007

FizzBuzz

So, this is pretty geeky, but I found it amusing.  My friend read this article which states that most computer programming candidates cannot actually program.  So, as is obviously neccesary when a blog article slaps you with a virtual glove, we each worked out our own little solution to the problem that was presented as an example of what candidates could typically not do:


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”.
Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary? The majority of comp sci graduates can't. I've also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.
So, this went back and forth a few times between us, escalating.  This morning, I emailed him this:
http://snippets.dzone.com/posts/show/3720
Turns out it actually runs faster than a one-liner in several situations because it only prints to STDOUT once rather than for every number.
Ahh, what are pointless fixations if not fun?
blog comments powered by Disqus