I'm trying to think of a way to match n players in teams of 3 (n most likely won't exceed 30 and is a multiple of 3). The matching will be based on their ranks (the lower the number, the more skilled the player is)
The target I thought was reasonable is that to match the players in teams, such that, the maximum difference between the teams' average rank (summation of each team's rank divided by 3) is as minimum as possible (i.e the difference between the highest team in average rank and lowest team in average rank should be as minimum as possible).
I thought about trying all possible permutations but that won't be possible since the complexity would be n! (and the input could very easily exceed 20 or more)
The only feasible (yet, very naive) solution I could think of goes like this: let's say we have 12 players the need to be matched in teams. We'll sort them based on rank, then divide the sorted list into 3 parts each containing 4 players (1st 4 players are most skilled, 2nd 4 players are average skilled, 3rd 4 players are least skilled), then I'll proceed to take the first player from the first part with the last player from the last part, 2nd player from first part with (last-1) from the last part etc....
Then I'll sort those 2s based on their average rank, and will proceed to put the 1st player from the middle part (2nd part) with the team who has the highest average rank, 2nd player from 2nd part with the team with 2nd highest average rank etc.....
This is of course not an optimal solution at all. So I was wondering if there was a feasible way to go about this problem that would produce a more optimal solution?
Thank you