in reply to Re: How can I improve this?
in thread How can I improve this?
I'm not really happy with the implementation of it, but I like it in spirit (of course, I'm a big fan of recursive algorithms to begin with).my $foo=permute('',[0..2],[0..2],[0..3],[0..2]); sub permute{ my $prefix=shift; my @arrays=@_; my $c=shift @arrays; my @ret=(); foreach(@$c){ my $f=$prefix.$_; if(scalar(@arrays)==0){ push @ret,$f; }else{ my $t=permute($f,@arrays); push @ret,@$t; } } return \@ret; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
My permutor
by merlyn (Sage) on Jul 25, 2000 at 07:57 UTC | |
by gryng (Hermit) on Jul 25, 2000 at 17:01 UTC | |
by Anonymous Monk on Oct 03, 2004 at 18:45 UTC |