Problem: Player 1 goes from 10 to 14, player 2 from 11 to 12.

Analysis of the possible solutions:

- you have the following possible individual match results

a1) 10:11

a2) 10:12

b1) 11:11

b2) 11:12

c1) 12:11

c2) 12:12

d1) 13:11

d2) 13:12

e1) 14:11

e2) 14:12

- Find an way to go over all possible (meaningful) match results for the given situation, e.g.

a b c d e 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 2 2 2 1 1 2 2 2 2 1 2 2 2 2 2

- deduce a general algorithm for the given approach to traverse all meaningful results (iterative or recursive). This is left for you as exercise. ;-)

[EDIT]

Ok, not really. After BillWoodruff's comments, I provide a solution here that is based on recursion.

C#static void playMatches(string[] scores, int iToPlay, int iCurr1, int iCurr2, int iEnd1, int iEnd2) { // play this match scores[scores.Length - iToPlay] = string.Format("{0}:{1}", iCurr1, iCurr2); // play the rest... // ...1st: all possible scores from this point on // when applying here all remaining permutations of player 1 scores for(int i = iCurr1+1; i <= iEnd1; ++i) { playMatches(scores, iToPlay-1, i, iCurr2, iEnd1, iEnd2); } // ...2nd: all possible scores from this point on // when applying here all remaining permutations of player 2 scores for (int i = iCurr2+1; i <= iEnd2; ++i) { playMatches(scores, iToPlay-1, iCurr1, i, iEnd1, iEnd2); } // last match: write whole score sequence if (iToPlay == 1) { Console.WriteLine(string.Join(" -> ", scores)); } }

Call it like this:C#int iScore1 = ...; int iScore2 = ...; int iEnd1 = ...; int iEnd2 = ...; int iMatches = iEnd1 + iEnd2 + 1 - iScore1 - iScore2; string[] scores = new string[iMatches]; playMatches(scores, iMatches, iScore1, iScore2, iEnd1, iEnd2);

The resulting output for your given data is10:11 -> 11:11 -> 12:11 -> 13:11 -> 14:11 -> 14:12 10:11 -> 11:11 -> 12:11 -> 13:11 -> 13:12 -> 14:12 10:11 -> 11:11 -> 12:11 -> 12:12 -> 13:12 -> 14:12 10:11 -> 11:11 -> 11:12 -> 12:12 -> 13:12 -> 14:12 10:11 -> 10:12 -> 11:12 -> 12:12 -> 13:12 -> 14:12

[/EDIT]

Cheers

Andi

Please fix the code first so that one can find out the logical problem in you program.

Cheers

Andi