3 ms·
It's certainly not perfect, but I came up with it under pressure in less than 90 seconds without checking online for the modulo return values, so I'm rather pro
by shanelja 14y ago
It's certainly not perfect, but I came up with it under pressure in less than 90 seconds without checking online for the modulo return values, so I'm rather proud of it.
<?php
$x = 1;
while($x <= 100)
{
if((($x % 5) == 0) && (($x % 3) != 0)){ print("Buzz");
}else{
if(($x % 3) == 0){
if(($x % 5) == 0)
{
print("FizzBuzz");
}
else
{
print("Fizz");
}
}else{
print($x);
}}
++$x;
}
?>
- PhearTheCeal 14y agoMy python solution: print "\n".join(["Fizz"*(i%3==0)+"Buzz"*(i%5==0)+str(i)*(i%5!=0 and i%3!=0) for i in range(1,101)])
- lifeisstillgood 14y agoI am a bit lost on the syntax, but its always good to check for division by 15 first. You have sort of caught that I think in 5 and not 3, but that just seems an odd idiom. The homepage shows a simple example in C. Oh, I used to use this on coding tests, the first guy who asked can I do it recursively in Scheme - I could have kissed him !