Say I have a list of players and I want to separate them into two teams of identical size. I want to know what are all the possibilities.
Here is some code that works if I have 16 players and want to know all possible combos of Team 1:
def potential_teams_of_8() do
num_players = 16
last = num_players - 1
# AWLOG the first player is on the team
for i1 <- 0..0,
i2 <- (i1 + 1)..(last - 6),
i3 <- (i2 + 1)..(last - 5),
i4 <- (i3 + 1)..(last - 4),
i5 <- (i4 + 1)..(last - 3),
i6 <- (i5 + 1)..(last - 2),
i7 <- (i6 + 1)..(last - 1),
i8 <- (i7 + 1)..last,
do: [i1, i2, i3, i4, i5, i6, i7, i8]
end
How do I make this function more general such that it can handle any number of players?
It’s slightly different than combinations. Combinations would give double the number of results.
Team1: 0,1,2,3,4,5,6,7
Team2: 8,9,10,11,12,13,14,15
is identical to
Team1: 8,9,10,11,12,13,14,15
Team2: 0,1,2,3,4,5,6,7
So the number of combos is halved.