[Shootout-list] External libraries and Fannkuch.pl
Joel Hoffman
hoffmanj@pacifier.com
Fri, 25 Mar 2005 18:13:57 -0800
This is a multi-part message in MIME format.
--------------060904000104070404090907
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Attached is a Perl Fannkuch program (using the official algorithm as
described) which uses Algorithm::FastPermute from CPAN. It is actually
not particularly fast, but at least I think it is easy to read!
I read Brent Fulgham's post about external libraries, but it's not clear
how repositories like CPAN are affected. It's really very normal (or at
least it should be) to use random modules from CPAN in everyday Perl
programming, but they aren't part of the core language. Some are pure
Perl and some (like this one) are implemented in C. I haven't seen
anything else using CPAN libraries, though, so is this acceptable?
Joel
--------------060904000104070404090907
Content-Type: application/x-perl;
name="fannkuch.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="fannkuch.pl"
#!/usr/bin/perl
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org
# contributed by Joel Hoffman
# To run: fannkuch.pl 9
#
use strict;
use Algorithm::FastPermute;
my $mx = 0;
my @array = (0..$ARGV[0]-1);
permute {
my @b = @array;
my $flips = 0;
while ((my $k = $b[0]) != 0) {
@b[0..$k] = reverse @b[0..$k];
$flips++;
}
$mx = $flips if $flips > $mx;
} @array;
print "Pfannkuchen($ARGV[0]) = $mx\n";
--------------060904000104070404090907--