Optimize order of a list based on time to complete, probability of success I'm a programmer participating in a coding challenge, but I'm not up on my advanced math. I'm currently working on a solution to a problem, and have a semi-functional program, but I'm still missing a couple of the test cases (black box, I don't have the cases, just pass/fail).
The problem involves between 2 and 50 processes that take m minutes to complete. Each process has a probability of success, provided as numerator and denominator. There is an upper bound to the denominator (1024) and the last process will always succeed. The example given is the following:
A - Takes 10 minutes, 1/2 chance of success
B - Takes 5 minutes, 1/5 chance of success

The answer asks for the "lexicographically first optimal list". For this case, [B, A] is the correct order because [B, A] takes an average of 12.5 minutes while [A, B] takes an average of 13 minutes. See: Time taken to give answer if probability is given.
I was able to write a recursive function to calculate the probabilities like above; I'm basically rotating the list and solving for the time, then sorting by average runtime. I'm close, but clearly missing some bigger concept. I've been mucking around in probability theory, permutations, combinatorics, etc. for a day or so, so I'm asking the following question: Is there a principle, theorem, law or field of mathematics that I should look into, or am I just mis-applying basic probability?
Thanks!
 A: Although your solution description is a bit light I think I understand that for each sequence of values in a list for i = 1, n ; 2 <= n <= 50 that you compute both a time and a lexical representation of the computation order.  As n > 2 you use a recursion to a method that adds the next increment of time to the total sum.   Then you rotate the list to generate a new ordered solution.  Finally you sort the resulting values by expected time and report the corresponding lex sequence.  As you say you "rotate" the list, I suppose you are careful to construct all possible permutations of the list entries. So it seems to me that you have the brute force solution required.  I'm a bit unclear what else you are looking for.  If you are looking for a more elegant solution (there may be one) it escapes me.  If you are still pondering why the statistical result explained in your other post is correct then perhaps you might consider reviewing the information at https://www.khanacademy.org/math/probability.  Good luck with your challenge.
