Reputation: 365
I’m facing a bit of a problem in one of my projects and I’m hoping you guys could bring some clarity to the matter.
The case is like this; I’ve got a group of 12 people divided into 4 groups. This is the initial line-up in a series of 3 rounds.
My problem I this; How can I re-render these groups, for the two following rounds, so that the people in the groups not before have met?
I want the re-rendered groups to be unique, eg. Person 1 shall never in the next two rounds join a group with either Person 2 or Person 3. And if Person 1 forms a group with Person 4 and Person 5 in the second round, these persons shall also be excluded in the last round.
Group 1
Person 1, Person 2, Person 3
Group 2
Person 4, Person 5, Person 6
Group 3
Person 7, Person 8, Person 9
Group 4
Person 10, Person 11, Person 12
Upvotes: 0
Views: 120
Reputation: 489
Sounds like you need a Combination algorithm. For more details on Combination like performance, etc check here and for code samples with explanation, you can check here.
Your specific implementation is Combination of 12 people taking 3 at a time with no repetition. This gives you 220 possible groups.
One way of checking if the same two people have been in a group before is to keep a record of the groups that have been formed and check any new groups against the record to see if the two groups being compared have any two people in common.
Upvotes: 1
Reputation: 37566
Try this:
for (i = 0 to NrGroups-1) do // NrGroups = 4
{
newGroup + (i+1) = Arr[i] +
Arr[(i+(Arr.length/NrPersonsInGroup))%Arr.length] +
Arr[(i+(Arr.length/NrPersonsInGroup+1))%Arr.length]; // NrPersonsInGroup = 3
}
Upvotes: 1