Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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!

In reply to Re: How can I improve this? by steveAZ98
in thread How can I improve this? by Dogg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (7)
    As of 2014-08-29 05:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (275 votes), past polls