FizzBuzz

I read an interesting article the other day, basically they stated that they challenge any programmer who applies to work with them to write a fizzbuzz program. This is a program that counts from 1 to 100, prints the numbers but if the number is divisible by 3 or divisible by five it would print the words fizz for 3, and buzz for 5.

Example:

1
2
fizz
4
buzz
fizz
7

Here is how I wrote it in PERL. (I'm sure it can be written easier, but I wrote this in just a couple minutes.)

#!/usr/bin/perl
$i=1;
while ($i <= 100)
{
if ($i%3==0) { $out= "fizz"; }
if ($i%5==0) { $out .= "buzz"; }
if ($out) {print "$out \n"} else { print "$i\n"; }
++$i;
undef ($out);
}

I know it's lame, but after reading the article, I wrote it just to see how easy it was to do.

-Fratm

Powered by Drupal - Design by artinet