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

P

phal

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
 
S

Sherm Pendley

phal said:
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--
 
S

Sisyphus

phal said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top