I want to create a league for table football where there is two people vs two people. There would be a match for every combination of pair vs every combination of pair. So, given the following players: A, B, C, D and E, the following games would be generated (I only included the games which player A was in but there would be other games too):
A,B vs C,D
A,B vs C,E
A,B vs D,E
A,C vs B,D
A,C vs B,E
A,C vs D,E
A,D vs B,C
A,D vs B,E
A,D vs C,E
A,E vs B,C
A,E vs B,D
A,E vs C,E
Is there an algorithm to do this easily? I could do this by hand if there was only 5 players but there is likely to be 10+.
You can do that automatically, yes.
Assume the players are numberd $1$ to $n$. Then:
That is, among all possible 4-tuples of different players, keep only [(a,b), (c,d)] with $a<b, a<c, c<d$. The purpose of picking only players "with a higher number" is to remove duplicates, as for instance, for playing purposes I assume [(1,2), (3,4)] is identical to [(3,4), (1,2)], [(2,1), (3,4)], [(1,2), (4,3)], [(2,1), (4,3)], [(4,3), (1,2)], [(3,4), (2,1)] and [(4,3), (2,1)]. But if you consider also the position of players within pairs, you can do that too: just change the conditions.
In Python:
For instance:
This can be done more shortly with:
But note that the number of such games grows quite quickly. For instance: