Competition: FizzBuzz
Posted: Wed Mar 07, 2007 4:54 am
A developer's community I was part of used to have these little competitions. They were fun and encouraged people to think and learn. Basically, the idea is to make a function/snippet that perform the functionality specific in the competition in the shortest amount of code. Whitespace, function names, variable names etc. do not matter. It's done on the following (I can't remember what it was exactly, so these can be changed):
Loops = 4
Built-in Functions = 2
Conditionals = 2
Variables = 1
The lowest score wins - creativity is also awarded. The first competition is to create a FizzBuzz application.

Here's my entry:
I know a loop would be easier, but I wanted to be a bit unique 
Loops = 4
Built-in Functions = 2
Conditionals = 2
Variables = 1
The lowest score wins - creativity is also awarded. The first competition is to create a FizzBuzz application.
The language is up to you, there will be an overall winner and a language specific winner. The winner gets nothing but it's funWrite 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”.
Here's my entry:
Code: Select all
array_walk(range(1, 100),'fizzbuzz');
function fizzbuzz($num){
print (($num % 3 == 0) ? 'Fizz'. (($num % 5 == 0) ? 'Buzz' : '') : (($num % 5 == 0) ? 'Buzz' : $num)) .' ';
}