# Figuring out The Best Team Combinations

I'm organizing a game tournament in a week. I began thinking about the best way to mathematically arrange the teams (so that they are really even, thus more competitive). So here's the data:

• 20 players in the event
• Each player is assigned a skill level (high number = skilled)
• 4 teams of 5 players each (although I'd prefer to build a algorithm that takes these as variables)
• I'm using a computer to solve the problem

So, I have 20 players. I'd like to generate 4 teams with 5 players each. To do this, I'd like to generate a list of all possible team combinations. To evaluate a team combination, I:

• Generate a combination of teams (a match)
• Sum the total skill for each team based off the players in that team
• Compare each team to each other, the highest difference between any two teams in the match is the "tolerance" level for that match. If the tolerance level is higher than a certain cap, the match is discarded

My current approach is to generate a base X number that is N digits long, where X is the number of teams I want, and N is the number of players. Then increment the base X number by 1, I'll get every possible team combination, and I can generate a list of matches that have low tolerance values.

The problem with this, as you probably know, is for 4 teams with 20 players, that's (4-1)^20 in base 3, which is 1E12 matches to check through. (This takes a long time on my computer). Is there a mathematical way to simplify this calculation to be doable in a short period of time?

By current method also allows for the possibility of uneven players spread across the number of teams, which is preferable. If this can't be present with a highly performant algorithm, then it's okay not to use it.

• What coding language are you using? – Joseph Eck Jun 1 '18 at 4:56
• I'm using Java @JosephEck – wdavies973 Jun 1 '18 at 4:58
• In its present form, this question is better suited for a site like Stack Overflow than for this one, as it's mainly about programming. You ask "Is there a mathematical way to simplify this calculation", but you haven't actually specified a mathematical problem, but rather (partially) described your current program. It seems that perhaps you're trying to solve the problem of finding all team combinations with "tolerance" levels below a certain threshold; that would be a well-defined mathematical problem, but that's currently not clear from the question. – joriki Jun 1 '18 at 6:24
• Thanks, I'll post over there. – wdavies973 Jun 2 '18 at 14:48