Forming a combination that is mathematically possible?

85 Views Asked by At

I have to implement an algorithm for a game. I will briefly explain the requirement for the team forming for the game.

The game consist of two teams selected randomly from a pool of players. There are two teams in the game. There must be at least 4 players to play this game. ie 2 players in each teams. One of the requirement of the game is that two players can not play in the same team for 3 times in a row. They can play together twice but not thrice. The following example will explain more:

Numbers of players : A,B,C,D,E,F

First round: (randomly selected from the pool of players) Team A: A,B,C Team B : D,E,F

Second round:(randomly selected from the pool of players) Team A: A ,B ,D Team B: E,F,C

Now in the third round of the game A B can not play together. I have written an algorithm that works until the number of players is 8. But as it goes behind 8. It does not work. I am wondering if this requirement is mathematically possible. If you have come across such problem then I would be appreciate your ideas and suggestion.

1

There are 1 best solutions below

5
On BEST ANSWER

Denote the two teams in each round by $0$ and $1$. Associate to each player $P$ a sequence $(P_{i})$ with values in $\{ 0, 1 \}$, where $P_{i}$ denotes the team in which $P$ plays at round $i$.

Consider the first three rounds. There are exactly $8 = 2^{3}$ sequences of $0$ and $1$ of length $3$. So if there are more than $8$ players, for at least two of them their sequences of length $3$ will be the same, which contradicts the rules of the game.

Many thanks to Nicholas, who corrected my misunderstanding of the game. The first two comments below refer to such a previous answer of mine.


Addendum Conversely, if there are $8$ players, there is always a solution. Assign to each player one of the $8$ distinct sequences in the first $3$ rounds, and then repeat this sequence periodically.