Sunday, 2007-01-28

FizzBuzz

Nearly flubbed this. Time constraints suck.

First implementation, aka bog-standard:

#!/usr/bin/perl -w
use strict;
my $i = 1;
while ( $i < 101 ) {
    if ( $i % 3 == 0 and $i % 5 == 0 ) {
    print "FizzBuzz\n";
    } elsif ( $i % 3 == 0 ) { 
    print "Fizz\n";
    } elsif ( $i % 5 == 0 ) {
    print "Buzz\n";
    } else {
    print "$i\n";
    }
    $i++
}

Maybe I’ll play a bit with this later… the online comments have degenerated into golfing in people’s favourite languages.

Check here for a funny-cause-it’s-true “example” in Java, everyone’s favourite enterprise language… (first comment).