Velocity Reviews > Perl > How make a letter ABC to ACB, BCA,....etc

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

phal
Guest
Posts: n/a

 09-08-2005
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

Sherm Pendley
Guest
Posts: n/a

 09-08-2005
"phal" <(E-Mail Removed)> 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

Sisyphus
Guest
Posts: n/a

 09-08-2005

"phal" <(E-Mail Removed)> 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:ermute or Algorithm::FastPermute (from cpan).

Cheers,
Rob

phal
Guest
Posts: n/a

 09-08-2005
thank very, for the information

Pal

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Edward A. Falk C Programming 1 04-04-2013 08:07 PM Gunter Henriksen Python 1 05-15-2009 07:03 AM vsgdp C++ 1 09-24-2005 08:01 PM Bruce Sam Java 15 11-19-2004 06:03 PM Jiong Feng ASP .Net 0 11-19-2003 05:29 AM

Advertisments