Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How can I improve this?

by steveAZ98 (Monk)
on Jul 25, 2000 at 07:34 UTC ( #24240=note: print w/ replies, xml ) Need Help??


in reply to How can I improve this?

Not sure that this is much of an improvement, but it only uses 5 for loops and one sort.

#!/usr/bin/perl -w my $m = []; $m->[0] = [1,2,3,4,0]; $m->[1] = [1,2,3,5,6]; $m->[2] = [1,2,3]; $m->[3] = [3,1,2]; $m->[4] = [3,2,1,0]; my $a = perms($m); foreach my $i (@{ $a }) { print "Item: $i\n"; } print "Total: ", $#{ $a }, "\n"; exit; sub perms { my ($m) = shift; my @a = (); my $n = 0; for my $a (0..$#{ $m->[0]}) { for my $b (0..$#{ $m->[1] }) { for my $c (0..$#{ $m->[2] }) { for my $d (0..$#{ $m->[3] }) { for my $e (0..$#{ $m->[4] }) { push @a, $m->[0]->[$a].$m->[1]->[$b].$m->[2]-> +[$c].$m->[3]->[$d].$m->[4]->[$ e]; } } } } } @a = sort @a; return \@a; }
but I agree with the idea of using the sort.
And you all beat me!


Comment on Re: How can I improve this?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://24240]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2014-10-02 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (56 votes), past polls