permutations of symbols?

Discussion in 'Perl Misc' started by Mike, Oct 14, 2009.

  1. Mike

    Mike Guest

    Does anyone have some simple code to give all the permutations of
    an array of symbols?

    i.e. for two symbols in an array:

    my @array = ('howard', 'geek');
    my @permutations = &permute(@array);

    print join(' ', $permutations[0]), "\n";
    print join(' ', $permutations[1]), "\n";

    howard geek
    geek howard

    It looks easy for two symbols. What about three, four, or more?

    Mike

    perl 5.8+
    Mike, Oct 14, 2009
    #1
    1. Advertising

  2. Mike <> wrote:
    >Does anyone have some simple code to give all the permutations of
    >an array of symbols?


    Anything wrong the answer to "perldoc -q permute"?

    jue
    Jürgen Exner, Oct 14, 2009
    #2
    1. Advertising

  3. Mike

    Mike Guest

    On 2009-10-14, Jürgen Exner <> wrote:
    > Mike <> wrote:
    >>Does anyone have some simple code to give all the permutations of
    >>an array of symbols?

    >
    > Anything wrong the answer to "perldoc -q permute"?
    >
    > jue


    I had found that, yes, thanks.
    Sure enough, after posting the question I find an acceptable answer.
    The tsc_permute looks more simple.
    <http://docstore.mik.ua/orelly/perl/cookbook/ch04_20.htm>

    Mike
    Mike, Oct 14, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karsten Wutzke

    Permutations of instances in array

    Karsten Wutzke, Mar 2, 2004, in forum: Java
    Replies:
    5
    Views:
    17,717
    Chris Lamprecht
    Mar 4, 2004
  2. Hendrik Maryns
    Replies:
    0
    Views:
    337
    Hendrik Maryns
    Mar 3, 2006
  3. Roger
    Replies:
    1
    Views:
    416
    Martin Magnusson
    Sep 24, 2003
  4. Ed Neukirch

    Permutations

    Ed Neukirch, Dec 24, 2003, in forum: C++
    Replies:
    7
    Views:
    608
    Mike Hewson
    Dec 27, 2003
  5. Daniel Fortin
    Replies:
    3
    Views:
    363
    Frank Schmitt
    Feb 18, 2004
Loading...

Share This Page