Re: Generate every possible combination

From: Date: Thu, 16 May 2002 09:23:15 +0000
Subject: Re: Generate every possible combination
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-97886@lists.php.net to get a copy of this message
Evan Nemerson wrote:
I need to generate every possible combination of the the values in an array. For example, if... $array = Array("A", "B", "C"); I really have no idea where to begin. The best lead I can think of is that there are going to be n! elements in the output array, where n is the size of the input array.
Correct, this also implies that using more than say 20 elements (20!) will take *loads* of CPU time and memory. Anyway, I did such a program once to test the performance of VB versus Java but alas I dont keep it around. It was recursive tho. A quick check on google came up with some code here: http://www.delphiforfun.org/Programs/Permutes_1.htm and som theory here: http://www.theory-of-evolution.org/Main/chap4/permutations_7.htm

« previous php.general (#97886) next »