Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jonasbn (1153)

  reversethis-{gro.napc} {ta} {nbsanoj}
AOL IM: BJonasN (Add Buddy, Send Message)

Perl Programmer located in Copenhagen, Denmark. Active member of Copenhagen Perl Mongers.

Author of:

  • Business::DK::CPR
  • Business::DK::CVR
  • Business::DK::PO
  • Business::OnlinePayment::CashCow
  • Date::Holidays
  • Date::Holidays::Abstract
  • Date::Holidays::Super
  • Date::Pregnancy
  • Games::Bingo
  • Games::Bingo::Bot
  • Games::Bingo::Print
  • Module::Info::File
  • Module::Template::Setup
  • Test::Timer

and maintainer of:

  • Tie::Tools
  • XML::Conf
  • Workflow

Journal of jonasbn (1153)

Tuesday January 21, 2003
06:25 AM

perlgolf and LISP come to use

[ #10097 ]

I am working on my Test framework and currently I am working on the scenario builder.

I needed to calculate the number of scenarios based on the combinations of parameter blocks, I could remember how to do this in a smart fashion, but I found my old LISP folder, which is following my develop directory.

And there it was, faculty.lsp, here is my Perl implementation:

sub faculty ($$) {
        my ($self, $i) = @_;

        return 1 if ($i <= 1);

        return $i *= $self->faculty($i - 1);

After this I started working on some code to create scenario combos and I remembered the Perlgolf tournament on permutations, and I located one of my readable revisions of my code for the tournament here. This is the revised version for use with the framework.

sub permute {
        my @items = @{ $_[0] };
        my @perms = @{ $_[1] };
        my $p = $_[2];

        unless (@items) {
                push(@{$p}, \@perms);

        } else {
                foreach $i (0 .. $#items) {
                        @newitems = @items;
                        @newperms = @perms;
                        unshift(@newperms, splice(@newitems, $i, 1));
                        permute([@newitems], [@newperms], $p);

Heh, fun to see when old stuff you got on your harddrive can be put to use.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I wonder why you wrote it as a method. OTOH, it's a bit annoying Perl makes such a huge distinction between methods and plain functions, for the function arguments.
    • Well actually it is not necessary but since I was using it in a class...

      I like it better just as a plain function myself.