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. Advertisements

  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. Advertisements

  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. Advertisements

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:
    18,035
    Chris Lamprecht
    Mar 4, 2004
  2. Hendrik Maryns
    Replies:
    0
    Views:
    468
    Hendrik Maryns
    Mar 3, 2006
  3. Roger
    Replies:
    1
    Views:
    516
    Martin Magnusson
    Sep 24, 2003
  4. Ed Neukirch

    Permutations

    Ed Neukirch, Dec 24, 2003, in forum: C++
    Replies:
    7
    Views:
    855
    Mike Hewson
    Dec 27, 2003
  5. Daniel Fortin
    Replies:
    3
    Views:
    497
    Frank Schmitt
    Feb 18, 2004
  6. John Trunek

    Permutations of a set

    John Trunek, Apr 5, 2004, in forum: C++
    Replies:
    10
    Views:
    1,099
    Rolf Magnus
    Apr 6, 2004
  7. jose luis fernandez diaz

    Combinations/permutations algorithm in C++

    jose luis fernandez diaz, Apr 13, 2004, in forum: C++
    Replies:
    6
    Views:
    14,443
    Leor Zolman
    Apr 13, 2004
  8. Alex Vinokur
    Replies:
    2
    Views:
    3,027
    Alex Vinokur
    May 13, 2004
Loading...