PHP FizzBuzz Test

Read again about the FizzBuzz test on Joey Devilla’s Global Nerdy blog today and got thinking about the solution. By no stretch of the imagination do I consider my self an amazing programmer, but I thought I should figure out an easy way to do this, should the occasion permit itself to do the test someday.

The basic requirement follows:

“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”.”

If any language is kosher, I chose PHP, and this is what I came up with:

[php]
$numbers = range(1,100);
foreach($numbers as $number) {
if( $number % 15 == 0 ) {
echo ‘FizzBuzz<br />’;
} elseif( $number % 5 == 0 ) {
echo ‘Buzz<br />’;
} elseif( $number % 3 == 0 ) {
echo ‘Fizz<br />’;
} else {
echo $number . ‘<br />’;
}
}
[/php]

After thinking about it, and to be a little closer to the requirements, you could rewrite it like this, just using a for loop. I’m filing this away as the theoretical best practice.

[php]
for($number = 1; $number <= 100; $number++) {
if( $number % 3 == 0 && $number % 5 == 0 ) {
echo ‘FizzBuzz’;
} elseif( $number % 5 == 0 ) {
echo ‘Buzz’;
} elseif( $number % 3 == 0 ) {
echo ‘Fizz’;
} else {
echo $number;
}

}
[/php]

Designers vs Coding

Good design and good markup provide structure to content. Good markup is a fundamental part of good design: beautiful on the inside, beautiful on the outside. HTML and CSS give another venue to provide structure to content in the native language of the web, and learning these guides decisions by surfacing the affordances of the medium. Design decisions are affected by both the content and the format, like how a sculptor would make different decisions if she were working with clay rather than marble.

via via Frank : Designers vs Coding.

April WordPress Meetup

Wanted to invite everyone back down to my house for another WordPress Meetup this week. We had a great turnout last time, and though my basement might be busting at the seams, we will do it there again.

Details:

When: Wednesday, April 15th, 2009 7:00 pm – whenever
Where: My house, 549 W. Goldenrod Way Saratoga Springs

Topics: Like last time, anything that you want to talk about. I just got a new TV that we can hook up laptops too, so bring your lappy, and examples of what you are working on.

Below are a some of the people that came last time, I hope that you all come again, and bring some friends too!

Feel free to bring a snack to share, I am thinking about looking for some exotic beverages… If you want to RSVP, just leave a comment letting me know you are coming. Then I can know how many chairs to steal from the church… Spread the word!