Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Created March 18, 2012 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/2073813 to your computer and use it in GitHub Desktop.
Save kenwebb/2073813 to your computer and use it in GitHub Desktop.
Monty Hall problem
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/wb/ (C) Ken Webb Sun Jun 10 2012 16:10:27 GMT-0400 (EDT)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Monty Hall problem
Description: The Monty Hall problem is a probability puzzle loosely based on the American television game show Let's Make a Deal and named after the show's original host, Monty Hall.
Url: http://en.wikipedia.org/wiki/Monty_Hall_problem
InternalName:
YoutubeId:
Keywords:
My Notes
--------
Several things I've read recently have mentioned the odd cognitive behavior associated with the Monty Hall problem. The wikipedia page provides a good description, so I think I understand it now, at least in theory. In this workbook I will work through the problem using a Xholon simulation.
The wikipedia page links to two external pages with simulations. Both of those pages are closed-source, which means that the code behind the simulations is not accessible. The New York Times simulation uses Adobe Flash, and the The Wolfram Demonstrations Project simulation uses a proprietary tool that must first be downloaded.
The wikipedia page includes the following "fully unambiguous, mathematically explicit" description of the problem ::
"Suppose you're on a game show and you're given the choice of three doors [and will win what is behind the chosen door]. Behind one door is a car; behind the others, goats [unwanted booby prizes]. The car and the goats were placed randomly behind the doors before the show. The rules of the game show are as follows: After you have chosen a door, the door remains closed for the time being. The game show host, Monty Hall, who knows what is behind the doors, now has to open one of the two remaining doors, and the door he opens must have a goat behind it. If both remaining doors have goats behind them, he chooses one [uniformly] at random. After Monty Hall opens a door with a goat, he will ask you to decide whether you want to stay with your first choice or to switch to the last remaining door. Imagine that you chose Door 1 and the host opens Door 3, which has a goat. He then asks you "Do you want to switch to Door Number 2?" Is it to your advantage to change your choice?"
The wikipedia page also includes several useful SVG graphics. These are open-source. Anyone can look inside the images and do whatever they want with them. I've downloaded and edited one of these images, and pasted it into the SVG section of this workbook. The following image is in the public domain::
http://upload.wikimedia.org/wikipedia/commons/7/79/Monty_closed_doors.svg
To play Let's Make a Deal, and experience the Monty Hall problem::
Press the Run button above.
Press the Step button in the overlay.
Click on one of the 3 doors in the SVG graphic.
]]></Notes>
<script implName="lang:python:inline:"><![CDATA[
#print "height = 12.34 m"
]]></script>
<script implName="lang:javascript:inline:"><![CDATA[
//print("height = 56.78 meters\n");
]]></script>
<_-.XholonClass>
<!-- domain objects -->
<PhysicalSystem/>
<MontyHallProblem/>
<Door/>
<Prize>
<Car/> <!-- the valuable prize -->
<Goat/> <!-- a booby prize -->
</Prize>
</_-.XholonClass>
<xholonClassDetails>
<MontyHallProblem/>
</xholonClassDetails>
<PhysicalSystem>
<MontyHallProblem>
<Door roleName="Door number 1"/>
<Door roleName="Door number 2"/>
<Door roleName="Door number 3"/>
</MontyHallProblem>
</PhysicalSystem>
<Blockbehavior implName="lang:python:inline:"><![CDATA[
# This works if pasted in as a last child of Block.
#height.incVal(0.02)
#print("Python wants something to do. Height:" + str(height))
]]></Blockbehavior>
<Blockbehavior implName="lang:javascript:inline:"><![CDATA[
// This works if pasted in as a last child of Block.
//height.incVal(0.02);
//print("JavaScript wants something to do. Height:" + height + "\n");
]]></Blockbehavior>
<MontyHallProblembehavior implName="lang:webEditionjs:inline:"><![CDATA[
function postConfigure() {
$("textarea#btstrp_console").css("font-size", "12px");
$("textarea#btstrp_console").attr("rows", "6");
$("textarea#btstrp_console").attr("cols", "70");
}
function act() {
// This script will automatically be inserted as the last child of the MontyHallProblem node,
// and will run each time step. Each time step is a new game.
var doors = this.siblings('.Door');
var doorWithCar = doors.eq(Math.floor(Math.random() * doors.length));
var doorsWithGoats = doors.not(doorWithCar);
var svg = $($('div#mySVGDiv > object')[0].contentDocument.getElementsByTagNameNS(svgns, 'svg')[0]);
var doorsSVG = svg.children().children().children().children('rect');
doors.each( function() {
var $this = $(this);
$this.children().remove();
if (this === doorWithCar[0]) {
$this.append('<div class="Car"></div>');
}
else {
$this.append('<div class="Goat"></div>');
}
});
doorsSVG.bind( 'click', function() {
var doorIndex = doorsSVG.index($(this));
$thisDoor = doors.eq(doorIndex);
print("\n\nYou have selected " + $thisDoor.attr('roleName') + ".");
var doorsWithGoatsX = doorsWithGoats.not($thisDoor);
var anotherDoor = doorsWithGoatsX.eq(Math.floor(Math.random() * doorsWithGoatsX.length));
print("\n" + anotherDoor.attr('roleName') + " has a Goat.");
var doorSwitchTo = doors.not($($thisDoor)).not(anotherDoor);
print("\nSwitch to " + doorSwitchTo.attr('roleName') + " by clicking on that door,\n or click again on your original door.");
doorsSVG.unbind('click');
doorsSVG.bind('click', function() {
var doorIndex = doorsSVG.index($(this));
$thisDoor = doors.eq(doorIndex);
print("\n" + $thisDoor.attr('roleName') + " has a " + $thisDoor.children().attr('class') + ".");
doorsSVG.unbind('click');
});
});
}
]]></MontyHallProblembehavior>
<Blockbehavior implName="lang:bsh:inline:"><![CDATA[
// This works if pasted in as a last child of Block.
//height.incVal(0.02);
//System.out.print("Java/Beanshell wants something to do. Height:" + height + "\n");
]]></Blockbehavior>
<Blockbehavior implName="lang:jruby:inline:"><![CDATA[
#require 'java'
# This works if pasted in as a last child of Block.
#$height.incVal(0.02)
#puts "Ruby wants something to do. Height: #{$height}"
]]></Blockbehavior>
<Blockbehavior implName="lang:groovy:inline:"><![CDATA[
// This works if pasted in as a last child of Block.
//height.incVal(0.02);
//System.out.print("Groovy wants something to do. Height:" + height + "\n");
]]></Blockbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.0"
width="150"
height="80"
id="svg2">
<g
transform="translate(-197.8125,-457.4375)"
id="layer1">
<title>Monty Hall problem</title>
<g
id="g3095">
<g>
<title>Door number 1</title>
<rect
width="38.088432"
height="78.088425"
x="198.76169"
y="458.3833"
id="MontyHallProblem/Door[1]"
style="fill:#5599ff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.91157269;stroke-miterlimit:4;stroke-opacity:1" />
</g>
<g>
<title>Door number 2</title>
<rect
width="38.088432"
height="78.088425"
x="253.76161"
y="458.3833"
id="MontyHallProblem/Door[2]"
style="fill:#5599ff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.91157269;stroke-miterlimit:4;stroke-opacity:1" />
</g>
<g>
<title>Door number 3</title>
<rect
width="38.088432"
height="78.088425"
x="308.76163"
y="458.3833"
id="MontyHallProblem/Door[3]"
style="fill:#5599ff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1.91157269;stroke-miterlimit:4;stroke-opacity:1" />
</g>
<path
d="m 238.54002,466.09964 a 3.9163287,4.0350051 0 1 1 -7.83266,0 3.9163287,4.0350051 0 1 1 7.83266,0 z"
transform="matrix(0.638353,0,0,0.619578,54.61876,208.6424)"
id="path2822"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<text
x="218.27669"
y="479.8735"
id="text2824"
xml:space="preserve"
style="font-size:12.52173901px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:100%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Arial"><tspan
x="218.27669"
y="479.8735"
id="tspan2826"
style="font-family:Arial">1</tspan></text>
<path
d="m 238.54002,466.09964 a 3.9163287,4.0350051 0 1 1 -7.83266,0 3.9163287,4.0350051 0 1 1 7.83266,0 z"
transform="matrix(0.638353,0,0,0.619578,109.6187,208.6424)"
id="path2830"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<text
x="272.95563"
y="478.99817"
id="text2832"
xml:space="preserve"
style="font-size:12.52173901px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:100%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Arial"><tspan
x="272.95563"
y="478.99817"
id="tspan2834"
style="font-family:Arial">2</tspan></text>
<path
d="m 238.54002,466.09964 a 3.9163287,4.0350051 0 1 1 -7.83266,0 3.9163287,4.0350051 0 1 1 7.83266,0 z"
transform="matrix(0.638353,0,0,0.619578,164.6187,208.6424)"
id="path2854"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none" />
<text
x="327.81787"
y="479.84424"
id="text2856"
xml:space="preserve"
style="font-size:12.30440617px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:100%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Arial"><tspan
x="327.81787"
y="479.84424"
id="tspan2858"
style="font-family:Arial">3</tspan></text>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment