r/dailyprogrammer_ideas • u/pier4r • Aug 14 '17
[Easy / intermediate] All the possible match days
Description:
Given N teams, with N even, we want to pair them to create a match day. Similarly as the one played on the weekend in some soccer leagues. Every team has only one opponent (and it must have one!). Every team appear in the match day.
The point is, how many valid match days are possible?
With four teams one has:
1 vs 2
3 vs 4
or
1 vs 3
2 vs 4
or
1 vs 4
2 vs 3
Input:
The number of teams. For example: "6". It means teams identified by the numbers: 1, 2, 3, 4, 5, 6 .
So try for 8 teams, 16 teams and 32 teams.
Output:
The number of valid match days given the number of the teams.
For example for 4 teams you should expect 3 match days. With 6 teams, 15 match days (thanks /u/JakDrako fro spotting the error).
Notes.
The upper bound of match days (not necessarily valid) can be computed as follow.
With N teams, we have N choose 2 possible pairings, let's call this number P. With P possible pairings, we can have P choose N/2 possible match days (not necessarily valid, like there will be many with the same team appearing more than one time, or a team does not appear at all).
- With 4 teams we have: 6 pairings , 15 match days as upper bound.
- 6 teams: 15 pairings, 455 match days as upper bound.
- 8 teams: 28 pairings, 20475 match days as upper bound.
- 16 teams: 120 pairings, 840261910995 match days as upper bound
- 32 teams: 496 pairings, 502231654686936153824108082819 match days as upper bound.
- 64 teams: 2016 pairings, 16448034663315894530880819868572146860903748179379773700987306512047075 match days as upper bound.
2
u/JakDrako Aug 14 '17
I think I'm missing something. With 6 teams, I get the following 15 pairings:
Why aren't all 15 valid "match days"... I don't get what brings the number down to 13...
0
u/[deleted] Aug 14 '17
[deleted] — view deleted comment