Programmer Fizzbuzz

Well it came up on slashdot, defined as typical short interview questions to get people to demonstrate coding abililty. The classic is swapping two ints without a temp variable, well anyway heres one for swapping two strings since it took my sleepy brain a few minutes to get going on it and I thought it was interesting

#!/usr/bin/perl -w

use strict;

my $one = "foowaffle";
my $two = "bar";

print "one: $onentwo: $twonn";

$one .= $two;

$two = substr($one, 0, (length($one) - length($two)));
$one = substr($one, length($two));

print "FIZZBUZZnnone: $onentwo: $twon";

Comment with your own versions.

Leave a Reply