{"id":3367,"date":"2019-07-08T15:11:18","date_gmt":"2019-07-08T15:11:18","guid":{"rendered":"https:\/\/robertjwallace.com\/?p=3367"},"modified":"2019-07-08T15:11:20","modified_gmt":"2019-07-08T15:11:20","slug":"monty-hall-paradox","status":"publish","type":"post","link":"https:\/\/robertjwallace.com\/es\/monty-hall-paradox\/","title":{"rendered":"Monty Hall Paradox"},"content":{"rendered":"\n<p>The basic premise is that there are three doors, behind one is a prize.  The contestant makes a guess as to which door has the prize.  In this case the odds of winning are one in three.  But after the guess is make the host of the game opens one of the two remaining doors, showing no prize behind it.  The question is should the contestant change his guess from the original door to the remaining closed door.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>The simplest was to understand this is to consider that two times out of three the prize will be behind the doors that the contestant did not  choose.  The host will always open a door that does not contain a prize. So two thirds of the time the remaining door will have the prize.  <\/p>\n\n\n\n<p>So, one time in three the spectator will choose the winning door, but two times in three they will win by switching.  Below is a simple Html\/Javascript program showing this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Html<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html>\n    &lt;head>\n        &lt;title> Monty Hall Paradox&lt;\/title>\n        &lt;script\n\t src=\"https:\/\/code.jquery.com\/jquery-3.4.1.slim.min.js\"\n\t integrity=\"sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=\"\n\t crossorigin=\"anonymous\">&lt;\/script>\n\t&lt;script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/numeral.js\/2.0.6\/numeral.min.js\">&lt;\/script>\t  \n        &lt;script type=\"text\/javascript\" src=\".\/scripts\/hall.js\">&lt;\/script>\n        &lt;style type=\"text\/css\">\n           body { padding:20px 100px;}\n        &lt;\/style>\n    &lt;\/head>\n    &lt;body>\n     &lt;div id=\"noswitch\">&lt;\/div>\n     &lt;div id=\"switch\">&lt;\/div>\n    &lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Javascript<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\n    Monty Hall paradox \n*\/\n$(function() \n{\n        \n    var cycles = 10000;\n    var wins = 0;\n    var losses = 0;\n    \n    var doors = [0,0,0];\n    \n    for (var i = 0; i&lt;cycles; i++)\n    {\n        \/\/ initialize the doors\n        doors = [0,0,0];\n        \/\/ randomly assign a winning doors\n        doors[Math.floor(Math.random() * 3)] = 1;\n        \/\/ make a guess\n        doors[Math.floor(Math.random() * 3)] == 1 ? wins += 1 : losses += 1;\n    }\n    var perwin = numeral((wins\/cycles)).format(\"00.0%\")\n    var perlose = numeral((losses\/cycles)).format(\"00.0%\")\n    $(\"#noswitch\").html(\"&lt;p>Play without switching doors:&lt;\/br>Wins: \"+wins + \" \"+perwin+\"&lt;br \/>Losses: \"+losses + \" \"+perlose+ \"&lt;br \/>&lt;\/p>\");\n    \n    wins = 0;\n    losses = 0;\n    var guess = 0;\n    var flag = false;\n    for (var i = 0; i&lt;cycles; i++)\n    {\n        \/\/ initialize doors\n        doors = [0,0,0]; \n        \/\/ randomly assign a winning doors\n        doors[Math.floor(Math.random() * 3)] = 1;\n        \/\/ make a guess\n        guess = doors[Math.floor(Math.random() * 3)];\n        \/\/ look at the other doors, if both are 0 then loss, else win\n        flag = false;\n        for (var j=0; j&lt; 3; j++)\n        {\n            if (j != guess &amp;&amp; doors[j] == 1)  \/\/ this door is one of the others and has the prize\n            {\n                flag = true;\n            }\n        }\n        flag == true ? wins += 1 : losses += 1;\n    }\n    perwin = numeral((wins\/cycles)).format(\"00.0%\")\n    perlose = numeral((losses\/cycles)).format(\"00.0%\")\n    $(\"#switch\").html(\"&lt;p>Play with switching doors:&lt;\/br>Wins: \"+wins + \" \"+perwin+\"&lt;br \/>Losses: \"+losses + \" \"+perlose+ \"&lt;br \/>&lt;\/p>\");\n});<\/code><\/pre>\n\n\n\n<p>Output of the above program<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Play without switching doors:\nWins: 3335 33.4%\nLosses: 6665 66.6%\n\nPlay with switching doors:\nWins: 6604 66.0%\nLosses: 3396 34.0%<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li> <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/www.google.com\/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwi-rYCZzKXjAhVeAZ0JHRGlAu8QFjAAegQIABAB&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMonty_Hall_problem&amp;usg=AOvVaw3MN8FkiAwA5honp6kfvr4g (opens in a new tab)\" href=\"https:\/\/en.wikipedia.org\/wiki\/Monty_Hall_problem\" target=\"_blank\">Wikipedia<\/a><\/li><li><a href=\"https:\/\/www.khanacademy.org\/partner-content\/wi-phi\/wiphi-metaphysics-epistemology\/probability-philosophy\/v\/the-monty-hall-problem\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Khan Academy Video (opens in a new tab)\">Khan Academy Video<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The basic premise is that there are three doors, behind one is a prize. The contestant makes a guess as to which door has the prize. In this case the odds of winning are one in three. But after the guess is make the host of the game opens one of the two remaining doors, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/robertjwallace.com\/es\/monty-hall-paradox\/\" class=\"more-link\">Continuar leyendo<span class=\"screen-reader-text\"> &#8220;Monty Hall Paradox&#8221;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_eb_attr":"","footnotes":""},"categories":[143],"tags":[],"class_list":["post-3367","post","type-post","status-publish","format-standard","hentry","category-computer-stuff"],"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"Bob","author_link":"https:\/\/robertjwallace.com\/es\/author\/admin\/"},"_links":{"self":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/3367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/comments?post=3367"}],"version-history":[{"count":3,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/3367\/revisions"}],"predecessor-version":[{"id":3370,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/posts\/3367\/revisions\/3370"}],"wp:attachment":[{"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/media?parent=3367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/categories?post=3367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robertjwallace.com\/es\/wp-json\/wp\/v2\/tags?post=3367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}