FizzBuzz Test
2012 Mar 7 05:26 PM MST | Math7 Programming18 PHP4 [2012]3
This is a controversial way to filter out noobs people who can’t program. Luckily for me, I did very well at it. So what is this challenge about?
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 "Fizz-Buzz".
Well, isn’t that easy… it only took me less than two minutes versus the people who either can’t do this or take a long time to.
<?php
// 70 second solution!
for($i=1;$i<;=100;++$i){
$a = !($i % 3);
$b = !($i % 5);
if($a) echo $b ? "Fizz-Buzz": "Fizz";
elseif($b) echo "Buzz";
else echo $i;
}