Not very graceful or the most efficient but it does the trick...
#############
use strict;
my @pool = ('A', 'B', 'C', 'D');
permute([(@pool)], []);
sub permute {
my @items = @{ $_[0] };
my @perms = @{ $_[1] };
unless (@items) {
my $perm = join ('', (reverse(@perms)));
print $perm . "\n";
} else {
my(@newitems,@newperms,$i);
foreach $i (0 .. $#items) {
@newitems = @items;
@newperms = @perms;
unshift(@newperms, splice(@newitems, $i, 1));
permute([EMAIL PROTECTED], [EMAIL PROTECTED]);
}
}
}
#####################
Mark
----- Original Message -----
From: "So Phal" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, September 08, 2005 9:35 AM
Subject: Help for this type of combination of letter
hi, everyone
How to write a perl program to generate the following combination of
a letter ABCD
ABCD
ABDC
ACBD
ADBC
ADCB
ACDB
BACD
BADC
BDAC
BCAD
BDCA
BCDA
CABD
CADB
CDBA
CBAD
CBDA
CDAB
DABC
DBAC
DACB
DCAB
DBCA
DCBA
I think it is possible to generate this letter,
the rule is: ABCD 1*2*3*4=24
if only ABC 1*2*3=6
Thank lots of your help
--
May GOD blesses you, and your family
=============================
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs