0

Given a set of $n$ teams, I would like to calculate how many different leagues exist. For a league, I mean a series of days, where in each day (with $\frac{n}{2}$ matches) every team plays a match against another team, and the total number of days $(n-1)$ produces the league, such that every team competed with every other team.

Calculating the combinations of pairs from a group of $n$ elements gives all the possible matches, and calculating the combinations of all the possible matches in groups of $\frac{n}{2}$ gives all the possible different days (the order is not important).

Matches and days can be easily calculated with $\frac{n!}{k!(n-k)!}$ but at this point, how to calculate all the possible combinations of matches in $n-1$ days, without having the same match more than once?

For example, for a group of 8 teams, there are 28 possible matches and a total of 105 possible days (4 matches each). The question is, how many leagues (series of 7 days) with everyone of the 28 matches disputed only once, do exist? Thanks for reading.

dzang
  • 103

1 Answers1

0

I implemented a brute-force calculation for this problem. Unless I made a mistake, the count for $n = 2, 4, 6, 8$ is respectively 1, 6, 720, 16511040. I couldn't find a match in OEIS, so this leads me to suspect there is no simple answer.

My Mathematica code for the $n=8$ case (I was to lazy to code a function that works directly for any $n$, but it should be obvious how to generalize):

<< Combinatorica`    
n = 8; X = Select[Involutions[n, Cycles], Length[#] == (n/2) &]; Sum[
     Y = Select[X, Intersection[X[[i]], #] == {} &];
     Sum[
      Z = Select[Y, Intersection[Y[[j]], #] == {} &];
      Sum[
       W = Select[Z, Intersection[Z[[k]], #] == {} &];
       Sum[
        VVV = Select[W, Intersection[W[[l]], #] == {} &];
        Length[VVV]
        , {l, 1, Length[W]}]
       , {k, 1, Length[Z]}]
      , {j, 1, Length[Y]}]
     , {i, 1, Length[X]}]

EDIT: The above code does not give the correct result. For $n=8$ the value should be 31449600, and the relevant OEIS sequence is https://oeis.org/A036981. Here is new code which should be correct, and is also much faster (it could be made even faster by exploiting the initial symmetry, but it's meant to be a brute-force script):

<< Combinatorica`  

Leagues[adj_, 0] := 1

Leagues[adj_, 1] := Length[adj]

Leagues[adj_, n_] :=
 (
  graph = AdjacencyGraph[adj];
  matchFound = False;
  Do[
   If[IsomorphicGraphQ[graph, CacheGraphs[n][[i]]],
    matchFound = True;
    val = CacheValues[n][[i]]]
   , {i, 1, Length[CacheGraphs[n]]}];
  If[matchFound, val,
   val = Sum[row = adj[[i]];
     itemCount = Total[row];
     newItems = Table[0, {itemCount}];
     j = 1;
     Do[If[row[[k]] == 1, newItems[[j]] = k; j++], {k, 1, 
       Length[row]}];
     newAdj = adj[[newItems, newItems]];
     Leagues[newAdj, n - 1]
     , {i, 1, Length[adj]}];
   graph = AdjacencyGraph[adj];
   AppendTo[CacheGraphs[n], graph];
   AppendTo[CacheValues[n], val];
   val]
  )

Result[n_]:= (
X = Select[Involutions[n, Cycles], Length[#] == (n/2) &];
Do[CacheGraphs[m] = {};
CacheValues[m] = {}, {m, 1, n}]; Leagues[
 Table[Boole[Intersection[X[[i]], X[[j]]] == {}], {i, 1, 
   Length[X]}, {j, 1, Length[X]}], n - 1])

With a few minutes of calculation it is able to also match the next term in the OEIS sequence, 444733651353600.

Incidentally, it seems the hardest part of the calculation in my new approach can be reduced to the graph isomorphism problem, which is not known to be in either P or NP-Complete.

  • Hi Meni, thanks a lot for your answer, indeed you made a mistake, since for n=8 the number is 31449600, which I was obtaining from a script I made. Nevertheless, your answer was very precious, since I had no idea of what the OEIS was, but I googled it and I was then able to find the sequence 1,6,720,31449600 which redirects here: https://oeis.org/A036981 and answers my question. Thanks! – dzang Mar 09 '17 at 17:28
  • @dzang Oh. It's funny because I've actually encountered this sequence while looking up the first 3 terms, but didn't notice the comment that indicates it answers your question. (OEIS has an answer for everything. I never should have doubted that.) I think I see my bug now, I don't have the correct number of days. – Meni Rosenfeld Mar 09 '17 at 18:03
  • @dzang PS. May I have a look at your script? Perhaps there are ways to do it that are simpler than those I had in mind... – Meni Rosenfeld Mar 09 '17 at 18:09
  • I wrote a script in Python, it's quite primitive but if you want to have a look at it, you can find it here: https://www.dropbox.com/s/m1wa8zdepniulya/calculate_leagues.py?dl=0 – dzang Mar 09 '17 at 21:58
  • thanks for the final edit, I don't know Mathematica, but it's impressive that you can do the calculation for the next number in minutes! My script takes 7 minutes for n=8, I didn't even dare to try with n=10 :) Great answer! – dzang Mar 09 '17 at 22:04
  • @dzang: Thanks. The key insight in my new script is that a naive calculation repeats the same sub-problems many times. To avoid repetition, it memoizes every result it calculates, and when it encounters a problem in the future it first checks if it is equivalent to one that it has already solved. – Meni Rosenfeld Mar 10 '17 at 09:49
  • Would it be possible to use your code to calculate the next number in the sequence? – dzang Mar 11 '17 at 01:27
  • @dzang: I very much doubt it, I suspect it would need to be very heavily optimized for that to work. But I've done a simple optimization and started running it, let's see if it ever finishes... – Meni Rosenfeld Mar 11 '17 at 23:16
  • @dzang: Well, it hasn't finished in 40 hours and there's no reason to believe it ever will. – Meni Rosenfeld Mar 13 '17 at 15:53