{"id":1083,"date":"2011-08-16T10:34:33","date_gmt":"2011-08-16T10:34:33","guid":{"rendered":"http:\/\/www.navision-blog.de\/2011\/08\/16\/some-special-monads-in-f-part-4-of-n-application-the-monty-hall-problem\/"},"modified":"2022-11-20T13:45:36","modified_gmt":"2022-11-20T13:45:36","slug":"some-special-monads-in-f-part-4-of-n-application-the-monty-hall-problem","status":"publish","type":"post","link":"http:\/\/www.navision-blog.de\/blog\/2011\/08\/16\/some-special-monads-in-f-part-4-of-n-application-the-monty-hall-problem\/","title":{"rendered":"Some special monads in F# &#8211; Part 4 of n &#8211; Application: The Monty Hall problem"},"content":{"rendered":"<p>In the <a href=\"http:\/\/www.navision-blog.de\/2011\/08\/15\/some-special-monads-in-f-part-3-of-n-distributionmonad\/\">last part of this blog series<\/a> I showed a DistributionMonad, which allows to perform queries to probability scenarios. Today we will use this monad in order to solve the famous <a href=\"http:\/\/en.wikipedia.org\/wiki\/Monty_Hall_problem\">Monty Hall problem<\/a>. This article is based on the excellent paper by Martin Erwig and Steve Kollmansberger called <a href=\"http:\/\/web.engr.oregonstate.edu\/~erwig\/papers\/PFP_JFP06.pdf\">&quot;Functional Pearls: Probabilistic functional programming in Haskell&quot;<\/a>.<\/p>\n<blockquote>\n<p>\u201cSuppose you&#8217;re on a game show, and you&#8217;re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what&#8217;s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, &quot;Do you want to pick door No. 2?&quot; Is it to your advantage to switch your choice?\u201d<\/p>\n<p align=\"right\">[<a href=\"http:\/\/en.wikipedia.org\/wiki\/Monty_Hall_problem\">problem definition from Wikipedia<\/a>]<\/p>\n<\/blockquote>\n<p>Let\u2019s start by modeling the first choice using the DistributionMonad:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/1148789.js\"> <\/script>  <\/p>\n<p>As we can see the solution is 1\/3 as we expected and if we don\u2019t switch, we stay with these odds. But if we switch we might improve the probability for a car. Remember the host will always remove a Goat after your first pick. Let\u2019s analyze the second pick if we switch:<\/p>\n<table border=\"1\" width=\"289\">\n<tbody>\n<tr>\n<th width=\"49\">Car behind<\/th>\n<th width=\"47\">First choice<\/th>\n<th width=\"47\">Temp. Outcome<\/th>\n<th width=\"62\">Host removes<\/th>\n<th width=\"67\">Switching to<\/th>\n<th width=\"62\">Outcome<\/th>\n<\/tr>\n<tr>\n<td width=\"49\">Door 1<\/td>\n<td width=\"47\">Door 1<\/td>\n<td width=\"62\">Car<\/td>\n<td width=\"62\">Door 2<\/td>\n<td width=\"67\">Door 3<\/td>\n<td width=\"62\">Goat<\/td>\n<\/tr>\n<tr>\n<td width=\"49\">Door 1<\/td>\n<td width=\"47\">Door 1<\/td>\n<td width=\"62\">Car<\/td>\n<td width=\"62\">Door 3<\/td>\n<td width=\"67\">Door 2<\/td>\n<td width=\"62\">Goat<\/td>\n<\/tr>\n<tr>\n<td width=\"49\">Door 1<\/td>\n<td width=\"47\">Door 2<\/td>\n<td width=\"62\">Goat<\/td>\n<td width=\"62\">Door 3<\/td>\n<td width=\"67\">Door 1<\/td>\n<td width=\"62\">Car<\/td>\n<\/tr>\n<tr>\n<td width=\"49\">Door 1<\/td>\n<td width=\"47\">Door 3<\/td>\n<td width=\"62\">Goat<\/td>\n<td width=\"62\">Door 2<\/td>\n<td width=\"67\">Door 1<\/td>\n<td width=\"62\">Car<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If the Car is behind door 2 or door 3 the situation is symmetrical and therefor we can conclude, the following:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/1148794.js\"> <\/script>  <\/p>\n<p>And if we run this, we get this nice solution:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/1148811.js\"> <\/script>  <\/p>\n<p>Next time I will show how we can use the DistributionMonad to solve <a href=\"http:\/\/www.navision-blog.de\/2011\/08\/17\/some-special-monads-in-f-part-5-of-n-application-poker\/\">some basic poker scenarios<\/a>.<\/p>\n<div style=\"font-size:0px;\"><a href=\"https:\/\/edpillsdenmark.dk\">https:\/\/edpillsdenmark.dk<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the last part of this blog series I showed a DistributionMonad, which allows to perform queries to probability scenarios. Today we will use this monad in order to solve the famous Monty Hall problem. This article is based on the excellent paper by Martin Erwig and Steve Kollmansberger called &quot;Functional Pearls: Probabilistic functional programming [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[448,8],"tags":[664,582],"_links":{"self":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1083"}],"collection":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":6,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"predecessor-version":[{"id":2022,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1083\/revisions\/2022"}],"wp:attachment":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}