{"id":1588,"date":"2016-12-03T22:05:10","date_gmt":"2016-12-04T04:05:10","guid":{"rendered":"http:\/\/www.laurentlessard.com\/bookproofs\/?p=1588"},"modified":"2016-12-09T12:09:10","modified_gmt":"2016-12-09T18:09:10","slug":"unmasking-the-secret-santas","status":"publish","type":"post","link":"https:\/\/laurentlessard.com\/bookproofs\/unmasking-the-secret-santas\/","title":{"rendered":"Unmasking the Secret Santas"},"content":{"rendered":"<p>This <a href=\"http:\/\/fivethirtyeight.com\/features\/can-you-unmask-the-secret-santas\/\">Riddler<\/a> puzzle is about the popular Secret Santa gift exchange game. Can we guess who our Secret Santa is?<\/p>\n<blockquote><p>\nThe 41 FiveThirtyEight staff members have decided to send gifts to each other as part of a Secret Santa program. Each person is randomly assigned one of the other 40 people on the masthead to give a gift to, and they can\u2019t give to themselves. After the Secret Santa is over, everybody naturally wants to find out who gave them their gift. So, each of them decides to ask up to 20 people who they were a Secret Santa for. If they can\u2019t find the person who gave them the gift within 20 tries, they give up. (Twenty co-workers is a lot of co-workers to talk to, after all.) Each person asks and answers individually \u2014 they don\u2019t tell who anyone else\u2019s Secret Santa is. Also, nobody asks any question other than \u201cWho were you Secret Santa for?\u201d<\/p>\n<p>If each person asks questions optimally, giving themselves the best chance to unmask their Secret Santa, what is the probability that everyone finds out who their Secret Santa was? And what is this optimal strategy? (Asking randomly won\u2019t work, because only half the people will find their Secret Santa that way on average, and there\u2019s about a 1-in-2 trillion chance that everyone will know.)\n<\/p><\/blockquote>\n<p>Here is my solution:<br \/>\n<a href=\"javascript:Solution('soln_secret_santa','toggle_secret_santa')\" id=\"toggle_secret_santa\">[Show Solution]<\/a><\/p>\n<div id=\"soln_secret_santa\" style=\"display: none\">\n<p>In order to generalize the problem, let&#8217;s assume there are $2n+1$ staff members in total, and each one is allowed to ask $n$ co-workers who they were Secret Santa for. The problem asks about $n=20$, but we&#8217;ll examine the general case here.<\/p>\n<p>A key aspect of this problem is that there is no communication among co-workers. Each staff member independent seeks to discover their Secret Santa and can&#8217;t use information gleaned by other co-workers. This assumption actually simplifies the problem greatly; from the point of view of the individual asking questions, there are two classes of co-workers: (1) those we know nothing about and (2) those for whom we already know either their Secret Santa or who they are Secret Santa for. A strategy consists of a sequence of decisions where we must either query somebody from group (1) or somebody from group (2). The lack of collusion among co-workers means that each staff member must use the same strategy. Consequently, there aren&#8217;t actually that many different possible strategies! Let&#8217;s look at each one in turn.<\/p>\n<h3>Purely random strategy<\/h3>\n<p>The simplest strategy is to choose $n$ co-workers at random. Each co-worker has a $\\tfrac{1}{2n}$ chance of being your Secret Santa, so the probability that you will find your Secret Santa is $\\tfrac{1}{2}$, regardless of the number of people. Since everybody must use the same strategy, the probability of everybody finding their Secret Santa is:<br \/>\n\\[<br \/>\nP_\\text{rand} = \\frac{1}{2^{2n+1}}<br \/>\n\\]This gets small very quickly as $n$ increases. When $n=20$, we have $P_\\text{rand} = 4.55\\times10^{-13}$ (about 1 in 2 trillion, as mentioned in the problem statement). A very small probability indeed. The random strategy maximizes an individual&#8217;s chance of finding their Secret Santa, but it&#8217;s a horrible choice if the goal is to maximize the chance that <em>everybody<\/em> finds their Secret Santa.<\/p>\n<h3>Deterministic strategy<\/h3>\n<p>If not picking randomly, there is only one alternative: to ask the co-worker you gifted! Once they reveal who they gifted, then you ask that person, and so on. You can imagine a graph where each node is a staff member, and you draw an arrow connecting each Secret Santa to their target. Once this is done, each node has exactly one incoming arrow (from their Secret Santa) and one outgoing arrow (to their target). An example of such a graph is shown below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa-300x126.png\" alt=\"secret_santa\" width=\"300\" height=\"126\" class=\"aligncenter size-medium wp-image-1595\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa-300x126.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa.png 652w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>Notice that the nodes form closed loops. There could be a single loop or multiple smaller loops, as shown above. Before we tackle the general case, let&#8217;s see what happens if the group is small.<\/p>\n<p><b>Small group<\/b> ($n=1$ or $n=2$): In the case $n=1$, there are three staff members, and they must necessarily be in a single cycle of length 3. In this case, we <i>immediately<\/i> know our Secret Santa; it&#8217;s the person we didn&#8217;t give a gift to! We don&#8217;t even need to ask any questions to know this. In the case $n=2$, there are five staff members. If they form a cycle of length 5, we can follow the Santa until there is a single co-worker left out. Since there can be no cycles of length 4, the co-worker that was left out must be our Secret Santa! Once again, we can deduce our Secret Santa with perfect accuracy even if we don&#8217;t directly ask them the question.<\/p>\n<p><b>Larger group<\/b> ($n\\ge 2$): If the group is larger, the deductive arguments used previously no longer work because there are too many co-workers left over after we&#8217;ve asked all our questions. Each staff member will find their Secret Santa only if all the loops in the are sufficiently small. Since $n$ questions are asked, each loop must have at most $n+1$ members. It turns out counting big loops is easier than counting small ones. So the probability we&#8217;re after is:<br \/>\n\\begin{align}<br \/>\nP_\\text{determ}<br \/>\n&#038;= \\frac{\\text{Assignments where each loop has at most }n+1\\text{ nodes}}{\\text{Total number of assignments}}\\\\<br \/>\n&#038;= 1-\\frac{\\text{Assignments containing a loop with at least }n+2\\text{ nodes}}{\\text{Total number of assignments}}\\\\<br \/>\n&#038;= 1-\\frac{\\sum_{k=n+2}^{2n+1}\\left(\\text{Assignments containing a loop with }k\\text{ nodes}\\right)}{\\text{Total number of assignments}}<br \/>\n\\end{align}The total number of assignments is the number of permutations of $\\{1,\\dots,2n+1\\}$ such that there are no fixed points, since nobody is allowed to be their own Secret Santa (wouldn&#8217;t be much of a secret). This is precisely the number of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Derangement\">derangements<\/a> $D_{2n+1}$, a concept we discussed in the <a href=\"https:\/\/laurentlessard.com\/bookproofs\/the-lonesome-king\/\">Lonesome King puzzle<\/a>.<\/p>\n<p>For the numerator, we must count how many ways we can have a loop of length $k$. Since $k \\ge n+2$, there are at most $n-1$ nodes left over. Therefore there can be no more than one loop of length $k$. There is ${2n+1\\choose k}$ ways of picking our loop, $(k-1)!$ ways of ordering the elements in the loop, and $D_{2n+1-k}$ ways of arranging the remaining nodes that weren&#8217;t part of the loop. Note that we don&#8217;t risk double counting in this manner because there aren&#8217;t enough nodes remaining to produce loops of length $k$ or greater. The final result is:<br \/>\n\\[<br \/>\nP_\\text{determ} = 1-\\frac{\\sum_{k=n+2}^{2n+1}{2n+1 \\choose k}(k-1)!\\,D_{2n+1-k}}{D_{2n+1}}<br \/>\n\\]In the case $n=20$, this evaluates to<br \/>\n\\begin{align}<br \/>\nP_\\text{determ} &#038;= \\tfrac{97939699570365313025758987280981560791683250767}{307662419905587585654556899376849633804439730767}\\\\<br \/>\n&#038;\\approx 0.318335<br \/>\n\\end{align}so a probability of about 31.8%. Not bad! Here is a plot of how the probability changes as a function of $n$.<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot.png\" alt=\"secret_santa_plot\" width=\"1491\" height=\"961\" class=\"aligncenter size-full wp-image-1615\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot.png 1491w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot-300x193.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot-768x495.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot-1024x660.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot-1200x773.png 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>As discussed above, the probability is equal to 1 when $n=1$ or $n=2$, since we can deduce the Secret Santa in those cases even if we ask the wrong co-workers. Curiously, the case $n=3$ (7 people) has a lower probability than the case $n=4$ (9 people). As $n\\to\\infty$, the probability tends to a finite limit. To find this limit, we can use the derangement formula $D_n = \\left[\\frac{n!}{e}\\right]$, where $[x]$ is the nearest integer to $x$. We then have:<br \/>\n\\begin{align}<br \/>\nP_\\text{determ} &#038;= 1-\\frac{\\sum_{k=n+2}^{2n+1}{2n+1 \\choose k}(k-1)!\\,D_{2n+1-k}}{D_{2n+1}} \\\\<br \/>\n&#038;\\approx 1-\\frac{\\sum_{k=n+2}^{2n+1}{2n+1 \\choose k}(k-1)!(2n+1-k)!}{(2n+1)!}\\\\<br \/>\n&#038;= 1-\\sum_{k=n+2}^{2n+1}\\frac{1}{k}\\\\<br \/>\n&#038;\\approx 1-\\log(2)\\\\<br \/>\n&#038;\\approx 0.306853<br \/>\n\\end{align}As $n\\to\\infty$, this approximation becomes exact and the limiting probability is $1-\\log(2)$, or about 30.7%. This can be shown rigorously by using upper and lower bounds for the derangements; i.e. $\\frac{k!}{e}-\\tfrac12 \\le D_k \\le \\frac{k!}{e}+\\tfrac12$.<\/p>\n<p>In the derivation above, we calculated the probability that <em>everybody<\/em> wins when everybody uses the deterministic strategy. If we&#8217;re interested in the probability that an individual wins using this strategy, we can observe that an individual wins as long as they don&#8217;t belong to the large chain of length $k$ in the summation above. So the probability that an individual wins is given by:<br \/>\n\\begin{align}<br \/>\nP_{\\text{determ}}^{\\text{individual}} &#038;= 1-\\frac{\\sum_{k=n+2}^{2n+1}{2n+1 \\choose k}(k-1)!\\,D_{2n+1-k}\\tfrac{k}{2n+1}}{D_{2n+1}}<br \/>\n\\end{align}Here is what a plot of this looks like as a function of $n$:<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot_individual.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot_individual.png\" alt=\"\" width=\"1598\" height=\"971\" class=\"aligncenter size-full wp-image-1617\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot_individual.png 1598w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot_individual-300x182.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot_individual-768x467.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot_individual-1024x622.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot_individual-1200x729.png 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>When $n > 2$, the probability of an individual winning is always less than 50%. When $n=20$, the probability that an individual wins is about 0.487805, or 48.8%. The limit as $n\\to\\infty$ can be computed as before and we obtain $\\tfrac{1}{2}$ this time. So in conclusion, the deterministic strategy is slightly worse than random guessing from the individual&#8217;s perspective, but it yields the best possible chance of <em>everybody<\/em> finding their Secret Santa.<\/p>\n<h3>Hybrid strategy<\/h3>\n<p>The nice thing about the purely random strategy is that no matter what the assignment looks like, there is always <em>some chance<\/em> that everyone will find their Secret Santa. In fact, the chance is the same for every assignment. Unfortunately, that chance is very low. In contrast, the deterministic strategy&#8217;s success depends heavily on the assignment. In some cases it works for everybody and in other cases it only works for some.<\/p>\n<p>In principle, one could design a <em>hybrid<\/em> strategy, e.g. using a deterministic strategy for some number of moves and then playing the remaining moves randomly. The potential of a hybrid strategy is that it gives every assignment a winning chance even if that chance is small. Unfortunately, such strategies are always worse than the purely deterministic one for this problem.<\/p>\n<p><!--\nThe last remaining option to consider is a hybrid strategy where sometimes we choose randomly and other times we choose deterministically. For example, we could use the strategy:\n\n\n<ol>\n\n\n<li>Use the deterministic strategy for the first $m$ moves, where $m \\le n$.\n\n\n<li>Play the remaining $n-m$ moves randomly.\n<\/ol>\n\n\nThe potential benefit of this strategy is that it gives every assignment a winning chance, even if that chance is small. When $m=0$, we recover the purely random strategy and when $m=n$ we recover the purely deterministic strategy. Let's see how the hybrid strategy fares...\n\nIn the case where $m$ is large, say $m=n-1$ or $m=n-2$, we can calculate the probability easily because only loops of length $k = m+2$ or larger matter and when $m$ is large enough, there can be at most one such loop. In those cases, a win is still possible if all loop members correctly guess their Secret Santa. This happens with probability $\\bigl(\\frac{n-m}{2n-m}\\bigr)^k$. Therefore, the probability of winning with the hybrid strategy is:\n\\begin{align}\nP_\\text{hybrid} &= 1-\\frac{\\sum_{k=m+1}^{2n+1}{2n+1 \\choose k}(k-1)!\\,D_{2n+1-k}\\left(1-\\bigl(\\frac{n-m}{2n-m}\\bigr)^k\\right)}{D_{2n+1}}\n\\end{align}Here is a plot comparing deterministic and hybrid strategies.\n\n<a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot2-1024x654.png\" alt=\"secret_santa_plot2\" width=\"840\" height=\"536\" class=\"aligncenter size-large wp-image-1607\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot2-1024x654.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot2-300x192.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot2-768x491.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot2-1200x767.png 1200w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2016\/12\/secret_santa_plot2.png 1509w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a>\n\nAs we can see, even the slightest hybridization (using a single random guess) produces inferior results when compared to the pure deterministic strategy. In the limit as $n\\to\\infty$, the random guesses get drowned out and we recover the same limit as before.\n--><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This Riddler puzzle is about the popular Secret Santa gift exchange game. Can we guess who our Secret Santa is? The 41 FiveThirtyEight staff members have decided to send gifts to each other as part of a Secret Santa program. Each person is randomly assigned one of the other 40 people on the masthead to &hellip; <a href=\"https:\/\/laurentlessard.com\/bookproofs\/unmasking-the-secret-santas\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Unmasking the Secret Santas&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1615,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[7],"tags":[9,6,8,2],"class_list":["post-1588","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-riddler","tag-binomial","tag-counting","tag-probability","tag-riddler"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/1588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/comments?post=1588"}],"version-history":[{"count":24,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/1588\/revisions"}],"predecessor-version":[{"id":1619,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/1588\/revisions\/1619"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media\/1615"}],"wp:attachment":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media?parent=1588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/categories?post=1588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/tags?post=1588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}