Add files via upload
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<div align=\"right\">Peter Norvig, Updated Sept 2018</div>\n",
|
||||
"\n",
|
||||
"# Scheduling a Doubles Pickleball Tournament\n",
|
||||
"\n",
|
||||
"My friend Steve asked for help in creating a schedule for a round-robin doubles pickleball tournament with 8 or 9 players on 2 courts. (*To clarify:* [Pickleball](https://en.wikipedia.org/wiki/Pickleball) is a paddle/ball/net game played on a court that is smaller than tennis. In this type of tournament a player plays with a different partner in each game.) \n",
|
||||
@@ -220,7 +222,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The astute reader may have noticed that `all_pairs(6)` has 15 pairs, and from that we can only make 7 games, not 7.5. We must drop one of the pairs, meaning that two players will never partner with each other, and will end up playing one less game than everyone else. Since there are *P* × *P*-1 / 2 pairs for *P* players, that means we will get an even number of pairs whenever either *P* or *P*-1 is divisble by 4."
|
||||
"The astute reader may have noticed that `all_pairs(6)` has 15 pairs, and from that we can only make 7 games, not 7.5. We must drop one of the pairs, meaning that two players will never partner with each other, and will end up playing one less game than everyone else. Since there are *P* × (*P*-1) / 2 pairs of *P* players, that means there are *P* × (*P*-1) / 4 games, and that is a whole number when either *P* or *P*-1 is divisble by 4."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -717,8 +719,7 @@
|
||||
" ([(1, 4), (2, 5)], [(3, 6), (8, 0)]),\n",
|
||||
" ([(5, 6), (4, 7)], [(1, 8), (2, 3)]),\n",
|
||||
" ([(1, 0), (3, 7)], [(2, 8), (4, 5)]),\n",
|
||||
" ([(3, 0), (2, 4)], [(6, 8), (5, 7)]) ])\n",
|
||||
"\n"
|
||||
" ([(3, 0), (2, 4)], [(6, 8), (5, 7)]) ])"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -790,7 +791,66 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"That's a very good schedule. It takes the minimum 15 rounds, and while not everyone playes everyone else 2 times, most are in the 1 to 3 range (with a couple of 4s and 0s). "
|
||||
"That's a very good schedule. It takes the minimum 15 rounds, and while not everyone plays everyone else 2 times, most counts are in the 1 to 3 range (except for pesky player 1, who faces 0 and B four times, and F zero times, and players 8 and B, who also do not play each other)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Addendum: Counting Schedules\n",
|
||||
"\n",
|
||||
"A reader asked \"*couldn't you have tried all possible schedules?*\" That's a great question! As [Ken Thompson says](https://users.ece.utexas.edu/~adnan/pike.html), \"when in doubt, use brute force.\" How many possible schedules are there? My first inclination was \"too many,\" even for *P* = 9, but is that really true? I'll count the number of schedules, approximately (that is, my formula will work exactly only for *P* where there is an even number of pairs and every round fills all the courts).\n",
|
||||
"\n",
|
||||
"- For *P* players, there are *P* × (*P* - 1) / 2 pairs of players.\n",
|
||||
"- We can place these pairs into the schedule in any order, so take the factorial of the number of pairs.\n",
|
||||
"- But that over-counts, because order doesn't matter in the following ways:\n",
|
||||
"- The order of pairs within a game doesn't matter, so divide by 2 (for each game).\n",
|
||||
"- The order of games within a round doesn't matter, so divide by the factorial of the number of courts (for each round).\n",
|
||||
"- The order of rounds in the schedule doesn't matter, so divide by the factorial of the number of rounds."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 50,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{4: 15,\n",
|
||||
" 5: 945,\n",
|
||||
" 6: 2027025,\n",
|
||||
" 7: 13749310575,\n",
|
||||
" 8: 28845653137679503125,\n",
|
||||
" 9: 7637693625347175036443671875}"
|
||||
]
|
||||
},
|
||||
"execution_count": 50,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from math import factorial as fact\n",
|
||||
"\n",
|
||||
"def combos(P):\n",
|
||||
" pairs = P * (P - 1) // 2 \n",
|
||||
" games = pairs // 2\n",
|
||||
" courts = P // 4\n",
|
||||
" rounds = games // courts\n",
|
||||
" return fact(pairs) // 2 ** games // fact(courts) ** rounds // fact(rounds)\n",
|
||||
"\n",
|
||||
"{P: combos(P) for P in range(4, 10)}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We see that it would have been feasible to try every schedule up to *P*=7, but not for any *P* beyond that."
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user