FizzBuzz
Syam Kumar April 06, 2007 11:33 PM IST
Imran says:
An example of a Fizz-Buzz question is the following:
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.
I’m not saying these people can’t write good code, but to do so they’ll take a lot longer to ship it. And in a business environment that’s exactly what you don’t want.
This sort of question won’t identify great programmers, but it will identify the weak ones. And that’s definitely a step in the right direction.
Link: Using FizzBuzz to Find Developers who Grok Coding - Imran On Tech
My try: ;-)
<?php
for($i =1; $i < 101; $i++)
{
if($i % 3 == 0) print "Fizz";
if($i % 5 == 0) print "Buzz";
if($i % 3 != 0 && $i % 5 != 0) print $i;
print "<br />";
}
?>
sunsuron May 18, 2007 11:16 PM