The FizzBuzz Test

Interesting way of determining how good a programmer is on Imran’s blog, called the FizzBuzz. I took it to make sure I wasn’t a crappy comp-sci grad who couldn’t program and discovered happily I could. Took just under four minutes to complete, though part of the extra time was I forgot how the ‘%’ operator in Perl worked (returns 0 not 1).

(A) Solution after the read more….


#!/usr/bin/perl -w
foreach my $i ( 1..100) {
if( not $i % 3 ) {
print “Fizz\n;
} elsif( not $i % 5 ) {
print “Buzz\n;
} else {
if( not $i % 3 and not $i % 5 ) {
print “FizzBuzz\n;
} else {
print “$i\n;
}
}
}

One Comment on “The FizzBuzz Test”

  1. Here’s mine:

    <?php
    for ($i=0;$i<=100;$i++) {
    $br=false;
    if (!is_float($i/3)) {
    echo "Fizz";
    $br = true;
    }
    if (!is_float($i/5)) {
    echo "buzz\r\n";
    $br=false;
    }
    if (is_float($i/3) and is_float($i/5)) {
    echo "$i\r\n";
    $br = false;
    }
    if ($br) {
    echo "\r\n";
    }
    }
    ?$gt;