How make a letter ABC to ACB, BCA,....etc

Discussion in 'Perl Misc' started by phal, Sep 8, 2005.

  1. phal

    phal Guest

    Dear all guru
    I have a problem in writing a Perl program to make a combination of
    letter which user type in.

    Type in= ABCD

    Output:
    ABCD
    ABDC
    ACBD
    ADBC
    ADCB
    ACDB

    BACD
    BADC
    BDAC
    BCAD
    BDCA
    BCDA

    CABD
    CADB
    CDBA
    CBAD
    CBDA
    CDAB

    DABC
    DBAC
    DACB
    DCAB
    DBCA
    DCBA

    The rule is that, if user type in only 3 letters so it will make a
    possible combination by 1*2*3 which is 6 conbination. On the above
    example, it is 1*2*3*4=24

    Thank very much for your help

    Take care
     
    phal, Sep 8, 2005
    #1
    1. Advertisements

  2. "phal" <> writes:

    > I have a problem in writing a Perl program to make a combination of
    > letter which user type in.
    >
    > Type in= ABCD
    >
    > Output:
    > ABCD
    > ABDC


    What you want to do is called "permutation". Sometimes knowing the keyword to
    search for can make all the difference. With that in mind, Google for "perl
    permutation algorithm", or go to <http://search.cpan.org> and search for
    "permutation".

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Sep 8, 2005
    #2
    1. Advertisements

  3. phal

    Sisyphus Guest

    "phal" <> wrote in message

    >
    > The rule is that, if user type in only 3 letters so it will make a
    > possible combination by 1*2*3 which is 6 conbination. On the above
    > example, it is 1*2*3*4=24
    >


    Use Algorithm::permute or Algorithm::FastPermute (from cpan).

    Cheers,
    Rob
     
    Sisyphus, Sep 8, 2005
    #3
  4. phal

    phal Guest

    thank very, for the information

    Pal
     
    phal, Sep 8, 2005
    #4
    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. Jiong Feng
    Replies:
    0
    Views:
    1,208
    Jiong Feng
    Nov 19, 2003
  2. Bruce Sam
    Replies:
    15
    Views:
    8,559
    John C. Bollinger
    Nov 19, 2004
  3. vertigo

    big letter -> small letter

    vertigo, Jul 6, 2004, in forum: Python
    Replies:
    4
    Views:
    1,027
    Reinhold Birkenfeld
    Jul 6, 2004
  4. Andrew McNamara

    Re: big letter -> small letter

    Andrew McNamara, Jul 6, 2004, in forum: Python
    Replies:
    2
    Views:
    902
    Scott David Daniels
    Jul 6, 2004
  5. vsgdp

    ABC inheriting from ABC

    vsgdp, Sep 24, 2005, in forum: C++
    Replies:
    1
    Views:
    491
    vsgdp
    Sep 24, 2005
  6. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    669
    Fredrik Lundh
    Aug 13, 2008
  7. Gunter Henriksen

    x.abc vs x['abc']

    Gunter Henriksen, May 13, 2009, in forum: Python
    Replies:
    1
    Views:
    541
    alex23
    May 15, 2009
  8. Replies:
    4
    Views:
    337
Loading...