A round robin tournament has `n` players. In each round, all players face each other **once**. Number of games per round is `n * (n-1) / 2`. Number of rounds is unlimited. Games are played one at a time without breaks, so the only way to get rest is to not play consecutive games.

How to find the best order of games with the following goals (in priority order)?

1. Maximize the smallest **length** of rest, i.e. the number of games before the same person plays again
2. Minimize the **count** of smallest rests per round
3. Divide the smallest rests as equally as possible among the players

I didn't figure out any other way to achieve this than the brute-force way: check each possible permutation and keep the best one in memory.

I had 7 people in my scenario. For `n = 7`, the count of games is `7 * 6 / 2 = 21`, meaning that the count of permutations is `21! = 51090942171709440000`. Of course, it's practically impossible to check that many permutations, so I ended up just implementing a program which creates random lists up to `m`. It was enough for my purposes at the time. The best permutation I found with this method (out of 100 million) had 9 one day rests and they were divided pretty equally among different players.

What is the most efficient way to get the best permutation?

For possible code examples I would prefer Java, JavaScript, or Swift.