Sorting all possible combinations
i´m trying to sort a list of combinations in a specific way. Consider the numbers 1-6 as teams, if every team can play on time against each other team we got this list as possible matches:
12 23 34 45 56
13 24 35 46
14 25 36
15 26
16
So now what i want is something like "matchdays":
12 13 14 15 16
34 46 26 24 23
56 25 35 36 45
As you can see after each block every team has one game, two games, ...
I could´n get a algorithm to sort the list this from:12 13 14 15 16 23 24 25 26 34 35 36 45 46 56
to
12 34 56 13 46 25 14 26 35 15 24 36 16 23 45
Additional: With odd team numbers the way to create matchdays gets even worse because you have to leave on team out for the d开发者_StackOverflow社区ay:
12 23 34 45
13 24 35
14 25
15
12 23 14 24 25
34 45 35 15 13
In the first block 5 is not playing in the second block 1 ist not playing....
Thank you for any help or ideas regarding this problem in c# with .net 4 possibly using Linq to manipulate the list.
SOLUTION:
Round-robin tournament
http://en.wikipedia.org/wiki/Round-robin_tournament Round Robin Tournament algorithm in C#You dont really need to sort this (from what I can see).
All you need to do is create 'sets' of 3 items, where an item is {A,B} for the 2 teams.
So for the start, pick any random item (and remove from list of all combinations), then you have say: {1,3}. Then choose another random number (and remove) where {A,B} != 1 or 3 for both A and B. The last step is easy, as you only have 2 options left. Pick any valid option, remove from list. Repeat 4 more times.
精彩评论