On Tue, Jun 14, 2005 at 11:03:29PM -0600, Dan Wilson wrote: > Ok folks, I need the help of some good mathematicians/programmers. I > know some of you are very good with this type of stuff and I am not. > > Given an array of elements (with an unknown length), I need to find all > possible combinations of that array. Say I have an array with the > values of: > > 'hey', 'you', and 'guys' > > I need an algorithm that allows me to combine each of these array > elements into a string... all combinations: > > "hey you guys" > "hey guys you" > "you hey guys" > "you guys hey" > "guys hey you" > "guys you hey" > > I'm sure I could pound this out, but I'm sure some of you have done this > in the past or know a specific algorithm that would do the trick. >
I would do this recursively. My PHP stinks, but something like this:
function hello($array)
{
foreach ($array as $i => $value) {
unset ($array[$i]);
print $element . hello($array);
$array[$i] = $value;
}
}
--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868
pgprZpslVMJxw.pgp
Description: PGP signature
.===================================. | This has been a P.L.U.G. mailing. | | Don't Fear the Penguin. | | IRC: #utah at irc.freenode.net | `==================================='
