I have a Algorithm problem. I have data that comes in an array:
Expand|Select|Wrap|Line Numbers
- $b = array( "A", "B", "C");
Expand|Select|Wrap|Line Numbers
- function fun($b){
- /*
- *Some code
- */
- return $result;
- }
array( "A", "B", "C")
or
array( "C", "B", "A")
fun will not produce same result. I need to pick the best result out of all possible results. So in this case I need to compare data from 6 different data sets:
array( "A", "B", "C")
array( "A", "C", "B")
array( "B", "A", "C")
array( "B", "C", "A")
array( "C", "A", "B")
array( "C", "B", "A")
that is 3! = 3 * 2 * 1 = 6 possible solutions
When data sample is so small as in this example there is no problems to this logic but lets imagine $b has only 10 elements. That gives us
10! = 10 * 9* 8 *7 *6 *5 *4 *3 *2 *1 = 3,628,800 possible solutions according to http://en.wikipedia.org/wiki/Factorial and that is sort of scenario I can expect with this application. Even better, I can expect number of elements to go over 1000 and 1000! is very very big number :))) so I need elegant solution (algorithm) as brutal force solution can be too brutal in this case.
I realize that this is maybe not the best place to post this problem as it is not strictly php problem but if I can only get a direction that would be much appreciated.
Thank You