I'm not sure which forum this should be in so please move if inappropriate.

I've tried several different approaches and have not been successful with any.

What I need is a routine that will take x amount of items (teams) and schedule them against each other.

This isn't a tournament (winners don't advance), just a normal schedule.

The rules are each team must play once per day and only play once per day, and each team must play every team once, and only once.

Also, there will always be an even number of teams.

So, for 6 teams the possible games will be:

1 vs. 2
1 vs. 3
1 vs. 4
1 vs. 5
1 vs. 6
2 vs. 3
2 vs. 4
2 vs. 5
2 vs. 6
3 vs. 4
3 vs. 5
3 vs. 6
4 vs. 5
4 vs. 6
5 vs. 6


In every iteration I can think it has a team missing a day, or teams playing the same team more than once.

What I have figured out is there must be x-1 days (if there are 6 teams it will take 5 days to schedule all games).

Is there an easier way to get this?

Well, the brute force method for this is to just make the list of all games that are to be played (as you have there) for x number of teams (btw. the number of teams have to be even for this to work, otherwise, every day there is one team with no opponent). Then you try every day (out of x+1 days) to come up with x / 2 games that can be played without one team being repeated amongst the pairs for that day. Then you eliminate all the selected games for that day from the total list of games left to be played and move on to the next day and repeat the process.

Of course, there must be a more clever way to do this, but that will work at least.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.