Permuting using any number of given chars

Discussion in 'Perl Misc' started by Brian Wakem, May 17, 2005.

  1. Brian Wakem

    Brian Wakem Guest

    I can use Algorithm::permute to output all permutations of 1 2 3

    123
    132
    312
    213
    231
    321


    But what I'm looking for is all possible permutations using any number of
    the input chars.

    Like this -

    1
    2
    3
    12
    13
    21
    23
    31
    32
    123
    132
    312
    213
    231
    321


    I can't think of a way right now and I can't find a module that does it.
    Any ideas?



    --
    Brian Wakem
    Brian Wakem, May 17, 2005
    #1
    1. Advertising

  2. Brian Wakem

    Anno Siegel Guest

    Brian Wakem <> wrote in comp.lang.perl.misc:
    > I can use Algorithm::permute to output all permutations of 1 2 3
    >
    > 123
    > 132
    > 312
    > 213
    > 231
    > 321
    >
    >
    > But what I'm looking for is all possible permutations using any number of
    > the input chars.
    >
    > Like this -
    >
    > 1
    > 2
    > 3
    > 12
    > 13
    > 21
    > 23
    > 31
    > 32
    > 123
    > 132
    > 312
    > 213
    > 231
    > 321
    >
    >
    > I can't think of a way right now and I can't find a module that does it.


    Split the problem. You know how to get all permutations for a given
    set. So find all subsets of the input characters ('', '3', '2', '23', '1',
    '13', '12', '123') and apply your solution to each.

    for ( subsets( '123') ) {
    print_permutations( $_);
    }

    The definition of subsets() is left as an exercise in recursion.

    Anno
    Anno Siegel, May 17, 2005
    #2
    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. Johannes Nix

    permuting letters and fairy tales

    Johannes Nix, Nov 11, 2004, in forum: Python
    Replies:
    19
    Views:
    561
    Steven Bethard
    Nov 17, 2004
  2. Kosio

    Floats to chars and chars to floats

    Kosio, Sep 16, 2005, in forum: C Programming
    Replies:
    44
    Views:
    1,285
    Tim Rentsch
    Sep 23, 2005
  3. Christian Meesters

    permuting over nested dicts?

    Christian Meesters, Oct 31, 2007, in forum: Python
    Replies:
    8
    Views:
    285
    Boris Borcic
    Nov 8, 2007
  4. Hongyu
    Replies:
    9
    Views:
    902
    James Kanze
    Aug 8, 2008
  5. M.Posseth

    receiving ??? chars instead of "special" chars

    M.Posseth, Nov 15, 2004, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    226
    Dan Rogers
    Nov 16, 2004
Loading...

Share This Page