{"id":3646,"date":"2023-05-21T10:47:06","date_gmt":"2023-05-21T15:47:06","guid":{"rendered":"https:\/\/laurentlessard.com\/bookproofs\/?p=3646"},"modified":"2023-05-22T14:56:27","modified_gmt":"2023-05-22T19:56:27","slug":"how-much-money-can-you-pull-out-of-a-hat","status":"publish","type":"post","link":"https:\/\/laurentlessard.com\/bookproofs\/how-much-money-can-you-pull-out-of-a-hat\/","title":{"rendered":"How much can you pull out of a hat?"},"content":{"rendered":"<p>This week&#8217;s <a href=\"https:\/\/fivethirtyeight.com\/features\/how-much-money-can-you-pull-out-of-a-hat\/\">Riddler Classic<\/a> is a strategy game about maximizing payout. What is the optimal strategy?<\/p>\n<blockquote><p>\nYou start with just the number 1 written on a slip of paper in a hat. Initially, there are no other slips of paper in the hat. You will draw from the hat 100 times, and each time you draw, you have a choice: If the number on the slip of paper you draw is k, then you can either receive k dollars or add k higher numbers to the hat.<\/p>\n<p>For example, if the hat were to contain slips with the numbers 1 through 6 and you drew a 4, you could either receive $4 or receive no money but add four more slips numbered 7, 8, 9 and 10 into the hat. In either case, the slip with the number 4 would then be returned to the hat.<\/p>\n<p>If you play this game perfectly \u2014 that is, to maximize the total amount of money you\u2019ll receive after all 100 rounds \u2014 how much money would you expect to receive on average?\n<\/p><\/blockquote>\n<p>My solution:<br \/>\n<a href=\"javascript:Solution('soln_moneyinhat','toggle_moneyinhat')\" id=\"toggle_moneyinhat\">[Show Solution]<\/a><\/p>\n<div id=\"soln_moneyinhat\" style=\"display: none\">\nWhen we are playing the game, there are two relevant variables: (1) the number of slips of paper in the hat, and (2) the number of draws remaining. We will therefore define the following quantity:<br \/>\n\\[<br \/>\nw(n,t) = \\left\\{<br \/>\n\\begin{array}{l}<br \/>\n\\text{Amount we can expect to win from this point} \\\\<br \/>\n\\text{forward, if there are }n\\text{ slips of paper in the hat} \\\\<br \/>\n\\text{and we have }t\\text{ draws remaining, assuming} \\\\<br \/>\n\\text{optimal play for the rest of the game.}<br \/>\n\\end{array}<br \/>\n\\right\\}<br \/>\n\\]The problem is asking us to calculate $w(1,100)$. We will do this by calculating in order: $w(n,0)$, $w(n,1)$, and so on, using a process called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dynamic_programming\">dynamic programming<\/a>. The idea is that the optimal strategy when there are $t+1$ draws remaining depends on the optimal strategy when there are $t$ draws remaining. So if we work our way backwards from $t=0$, we can derive the strategy for any $t$.<\/p>\n<ul>\n<li> When $t=0$, the game is over, so we have $w(n,0)=0$ for all $n$.\n<li> When $t=1$, we are on our last turn, so there is no benefit to adding more slips of paper to the hat. In this case, we should always take the money. How much money will this be, on average? There are $n$ slips of paper, so we can expect to win $w(n,1) = \\frac{1}{n}\\left(1+2+\\cdots+n\\right) = \\frac{n+1}{2}$. Therefore,<br \/>\n\\[<br \/>\nw(n,1) = \\frac{n+1}{2}.<br \/>\n\\]<\/p>\n<li> When $t=2$, we have to think more carefully. Suppose we draw the slip numbered $k$ from the hat. If we take the money, then we will pocket $k$ dollars and then earn on average $w(n,1)$ next turn. If instead we add more slips of paper to the hat, we will pocket nothing, but earn on average $w(n+k,1)$ next turn. Comparing these two quantities:<br \/>\n\\[<br \/>\nk + w(n,1) = k + \\frac{n+1}{2}\\qquad\\text{is larger than}\\qquad<br \/>\nw(n+k,1) = \\frac{n+k+1}{2}<br \/>\n\\]Therefore, it is always in our best interest to take the money when there are two turns remaining. When we do this, we will, on average, earn<br \/>\n\\[<br \/>\nw(n,2) = \\frac{1}{n}\\sum_{k=1}^n \\left( k + \\frac{n+1}{2} \\right) = n+1.<br \/>\n\\]<\/p>\n<li> The step $t=3$ is similar to $t=2$. We need to decide whether $k+w(n,2)$ is larger or smaller than $w(n+k,2)$. In this case, we have<br \/>\n\\[<br \/>\nk+w(n,2) = n+k+1\\qquad\\text{is equal to}\\qquad w(n+k,2) = n+k+1<br \/>\n\\]So both choices earn the same on average. In either case, we obtain<br \/>\n\\[<br \/>\nw(n,3) = \\frac{1}{n}\\sum_{k=1}^n \\left( n+k+1 \\right) = \\frac{3}{2}(n+1)<br \/>\n\\]<\/p>\n<li> When $t = 4$, it is always best to add more slips of paper. This is because<br \/>\n\\[<br \/>\nk+w(n,3) = k+\\frac{3}{2}(n+1)\\qquad\\text{is smaller than}\\qquad w(n+k,3)=\\frac{3}{2}(n+k+1)<br \/>\n\\]And when choosing the larger one, we obtain<br \/>\n\\[<br \/>\nw(n,4) = \\frac{1}{n}\\sum_{k=1}^n \\frac{3}{2}(n+k+1) = \\frac{9}{4}(n+1).<br \/>\n\\]\n<\/ul>\n<p>It turns out we can continue in this fashion and prove that whenever $n\\geq 4$, it is always better to add more slips of paper. We can show this using <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mathematical_induction\">induction<\/a>. Based on the pattern we&#8217;ve observed so far, we observe that $w(n,t) = \\left(\\frac{3}{2}\\right)^{t-2}(n+1)$ for $t=2,3,4$. To show that the pattern continues for larger $t$, suppose it holds for a given $t\\geq 3$. To compute $t+1$, we notice that<br \/>\n\\[<br \/>\nk+w(n,t) = k+\\left(\\frac{3}{2}\\right)^{t-2}(n+1)\\quad\\text{is smaller than}\\quad w(n+k,t) = \\left(\\frac{3}{2}\\right)^{t-2}(n+k+1)<br \/>\n\\]Therefore, we should add more slips of paper, and we obtain<br \/>\n\\begin{align}<br \/>\nw(n,t+1) &#038;= \\frac{1}{n}\\sum_{k=1}^n \\left(\\frac{3}{2}\\right)^{t-2}(n+k+1) \\\\<br \/>\n&#038;= \\frac{1}{n}\\left(\\frac{3}{2}\\right)^{t-2}\\sum_{k=1}^n (n+k+1) \\\\<br \/>\n&#038;= \\left(\\frac{3}{2}\\right)^{t-1}(n+1)<br \/>\n\\end{align}which verifies that our pattern continues for $t+1$, and by induction, it continues for all larger $t$. We therefore have the formula:<\/p>\n<p style=\"text-align: center;\"><span style=\"background-color: #AFC8E6; padding: 25px 10px 25px 10px;\">$\\displaystyle<br \/>\nw(n,t) = \\begin{cases}<br \/>\n\\left(\\frac{3}{2}\\right)^{t-2}(n+1) &#038; \\text{for }t\\geq 2 \\\\<br \/>\n\\frac{n+1}{2} &#038; \\text{for }t=1<br \/>\n\\end{cases}<br \/>\n$<\/span><\/p>\n<p>Returning to the original question, we can compute $w(1,100)$:<br \/>\n\\[<br \/>\nw(1,100) = \\left(\\frac{3}{2}\\right)^{98}(1+1) = \\frac{3^{98}}{2^{97}}<br \/>\n\\]So if we play optimally, we can expect to win approximately \\$361,387,713,364,635,766.57, or about 361 quadrillion dollars!<\/p>\n<p>Of course, this is only an <em>average<\/em>. In general, there will be a very large variability in how much we actually win! Here is a plot of the distribution of winnings (one million trials) along with the average shown as a vertical line. The distribution is heavily skewed, so I plotted the winnings on a log scale. This skewness is manifested in the fact that although the average is about $3.6\\times 10^{17}$, the median is only $5.3 \\times 10^{16}$. So on average we win a lot, but <em>most of the time<\/em> we win about 7 times less.<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2023\/05\/money_hat.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2023\/05\/money_hat.png\" alt=\"\" width=\"1445\" height=\"1097\" class=\"aligncenter size-full wp-image-3657\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2023\/05\/money_hat.png 1445w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2023\/05\/money_hat-300x228.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2023\/05\/money_hat-1024x777.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2023\/05\/money_hat-768x583.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2023\/05\/money_hat-1200x911.png 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This week&#8217;s Riddler Classic is a strategy game about maximizing payout. What is the optimal strategy? You start with just the number 1 written on a slip of paper in a hat. Initially, there are no other slips of paper in the hat. You will draw from the hat 100 times, and each time you &hellip; <a href=\"https:\/\/laurentlessard.com\/bookproofs\/how-much-money-can-you-pull-out-of-a-hat\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How much can you pull out of a hat?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3657,"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":[16,8,2],"class_list":["post-3646","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-riddler","tag-dynamic-programming","tag-probability","tag-riddler"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/3646","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=3646"}],"version-history":[{"count":12,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/3646\/revisions"}],"predecessor-version":[{"id":3660,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/3646\/revisions\/3660"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media\/3657"}],"wp:attachment":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media?parent=3646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/categories?post=3646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/tags?post=3646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}