Skip to content

Instantly share code, notes, and snippets.

@tonmcg
Last active August 18, 2017 02:07
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 tonmcg/d83cb1dee8602e8292a73f40fa01471c to your computer and use it in GitHub Desktop.
Save tonmcg/d83cb1dee8602e8292a73f40fa01471c to your computer and use it in GitHub Desktop.
Bayesian Statistics
border: no
license: gpl-3.0

This line graph shows the results of a running a simulation numerous times on the probability of winning (or losing) the Monty Hall door switch game. The blue line represents the probablity of winning the game if the contestant switches doors after being shown the "booby prize" door. The orange line shows the probability of losing if the contestant switches doors.

The game is based on classic Bayesian statistics. I wrote a Python script to run the simulation 1,000 times and output the probabilities of winning and losing over each simulation.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bayesian Statistics</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lora">
<style>
body {
font-family: 'Lora', serif;
}
path.line {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
path.area {
fill: #e7e7e7;
}
.axis {
shape-rendering: crispEdges;
}
.x.axis line {
stroke: #fff;
}
.x.axis .minor {
stroke-opacity: .5;
}
.x.axis path {
display: none;
}
.y.axis line,
.y.axis path {
fill: none;
stroke: #000;
}
.guideline {
margin-right: 100px;
float: right;
}
</style>
<!-- D3 -->
<script charset="utf-8" src="https://d3js.org/d3.v3.min.js" type="text/javascript"></script>
<!-- D3 Queue -->
<script charset="utf-8" src="https://d3js.org/d3-queue.v3.min.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-12">
<div id="title" class="page-header">
<h2>Bayesian Statistics <small>Simulating the Monty Hall Problem with Python</small></h2>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-12">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" value="" id="show_guideline">
Show Guideline & Curtain
</label>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-12">
<svg></svg>
</div>
</div>
</div>
<script defer type="text/javascript">
"use strict";
var margin = {
top: 80,
right: 80,
bottom: 80,
left: 80
},
width = 1200 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// Scales and axes. Note the inverted domain for the y-scale: bigger is up!
var x = d3.scale.linear().range([0, width]),
y = d3.scale.linear().range([height, 0]),
xAxis = d3.svg.axis().scale(x).tickSize(-height).tickSubdivide(true),
yAxis = d3.svg.axis().scale(y).ticks(4).orient("right");
// An area generator, for the light fill.
var area = d3.svg.area()
.interpolate("monotone")
.x(function(d) {
return x(d.id);
})
.y0(height)
.y1(function(d) {
return y(d.value);
});
// A line generator, for the dark stroke.
var line = d3.svg.line()
.interpolate("monotone")
.x(function(d) {
return x(d.id);
})
.y(function(d) {
return y(d.value);
});
// get the data
function getData() {
var endpointUrl = 'https://gist.githubusercontent.com/tonmcg/d83cb1dee8602e8292a73f40fa01471c/raw/c3bd8a8c333a1cea787337085bb78f01f782eca9/simulations.csv';
// using d3 Queue to simplify the use of deferreds while awaiting data to load from external sources
d3.queue()
.defer(d3.csv, endpointUrl)
.await(createViz);
}
// create visualization
function createViz(error,data) {
var switchValues = data.map(function(g) {
return {
id: +g[''],
name: 'switch',
value: +g['switch doors']
};
});
var stayValues = data.map(function(g) {
return {
id: +g[''],
name: 'stay',
value: +g['do not switch doors']
};
});
var values = d3.merge([switchValues, stayValues]);
// Compute the minimum and maximum date, and the maximum price.
x.domain(d3.extent(values, function(d) {
return d.id;
}));
y.domain(d3.extent(values, function(d) {
return d.value;
})).nice();
// Add an SVG element with the desired dimensions and margin.
var svg = d3.select("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
// Add the clip path.
svg.append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", width)
.attr("height", height);
// Add the x-axis.
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
// Add the y-axis.
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + width + ",0)")
.call(yAxis);
var colors = d3.scale.category10();
svg.selectAll('.line')
.data([switchValues,stayValues])
.enter()
.append('path')
.attr('class', 'line')
.style('stroke', function(d) {
return colors(Math.random() * 50);
})
.attr('clip-path', 'url(#clip)')
.attr('d', function(d) {
return line(d);
});
/* Add 'curtain' rectangle to hide entire graph */
var curtain = svg.append('rect')
.attr('x', -1 * width)
.attr('y', -1 * height)
.attr('height', height)
.attr('width', width)
.attr('class', 'curtain')
.attr('transform', 'rotate(180)')
.style('fill', '#ffffff');
/* Optionally add a guideline */
var guideline = svg.append('line')
.attr('stroke', '#333')
.attr('stroke-width', 0)
.attr('class', 'guide')
.attr('x1', 1)
.attr('y1', 1)
.attr('x2', 1)
.attr('y2', height);
/* Create a shared transition for anything we're animating */
var t = svg.transition()
.delay(750)
.duration(6000)
.ease('linear')
.each('end', function() {
d3.select('line.guide')
.transition()
.style('opacity', 0)
.remove();
});
t.select('rect.curtain')
.attr('width', 0);
t.select('line.guide')
.attr('transform', 'translate(' + width + ', 0)');
d3.select("#show_guideline").on("change", function(e) {
guideline.attr('stroke-width', this.checked ? 1 : 0);
curtain.attr("opacity", this.checked ? 0.75 : 1);
});
}
getData();
</script>
</body>
</html>
switch doors do not switch doors
0 100.0 0.0
1 100.0 0.0
2 100.0 0.0
3 100.0 0.0
4 100.0 0.0
5 100.0 0.0
6 100.0 0.0
7 100.0 0.0
8 100.0 0.0
9 100.0 0.0
10 90.9090909090909 9.090909090909092
11 91.66666666666666 8.333333333333332
12 92.3076923076923 7.6923076923076925
13 92.85714285714286 7.142857142857142
14 93.33333333333333 6.666666666666667
15 93.75 6.25
16 94.11764705882352 5.88235294117647
17 94.44444444444444 5.555555555555555
18 94.73684210526315 5.263157894736842
19 95.0 5.0
20 95.23809523809523 4.761904761904762
21 90.9090909090909 9.090909090909092
22 91.30434782608695 8.695652173913043
23 91.66666666666666 8.333333333333332
24 92.0 8.0
25 92.3076923076923 7.6923076923076925
26 92.5925925925926 7.4074074074074066
27 92.85714285714286 7.142857142857142
28 89.65517241379311 10.344827586206897
29 90.0 10.0
30 90.32258064516128 9.67741935483871
31 90.625 9.375
32 90.9090909090909 9.090909090909092
33 88.23529411764706 11.76470588235294
34 88.57142857142857 11.428571428571429
35 86.11111111111111 13.88888888888889
36 86.48648648648648 13.513513513513514
37 86.8421052631579 13.157894736842104
38 87.17948717948718 12.82051282051282
39 87.5 12.5
40 87.8048780487805 12.195121951219512
41 88.09523809523809 11.904761904761903
42 86.04651162790698 13.953488372093023
43 86.36363636363636 13.636363636363635
44 86.66666666666667 13.333333333333334
45 86.95652173913044 13.043478260869565
46 87.2340425531915 12.76595744680851
47 87.5 12.5
48 85.71428571428571 14.285714285714285
49 86.0 14.000000000000002
50 86.27450980392157 13.725490196078432
51 86.53846153846155 13.461538461538462
52 86.79245283018868 13.20754716981132
53 87.03703703703704 12.962962962962962
54 85.45454545454545 14.545454545454545
55 85.71428571428571 14.285714285714285
56 85.96491228070175 14.035087719298245
57 86.20689655172413 13.793103448275861
58 84.7457627118644 15.254237288135593
59 85.0 15.0
60 85.24590163934425 14.754098360655737
61 85.48387096774194 14.516129032258066
62 85.71428571428571 14.285714285714285
63 85.9375 14.0625
64 84.61538461538461 15.384615384615385
65 84.84848484848484 15.151515151515152
66 85.07462686567165 14.925373134328357
67 85.29411764705883 14.705882352941178
68 85.5072463768116 14.492753623188406
69 85.71428571428571 14.285714285714285
70 85.91549295774648 14.084507042253522
71 86.11111111111111 13.88888888888889
72 86.3013698630137 13.698630136986301
73 86.48648648648648 13.513513513513514
74 86.66666666666667 13.333333333333334
75 86.8421052631579 13.157894736842104
76 85.71428571428571 14.285714285714285
77 85.8974358974359 14.102564102564102
78 84.81012658227847 15.18987341772152
79 83.75 16.25
80 82.71604938271605 17.28395061728395
81 82.92682926829268 17.073170731707318
82 83.13253012048193 16.867469879518072
83 83.33333333333334 16.666666666666664
84 82.35294117647058 17.647058823529413
85 82.55813953488372 17.441860465116278
86 82.75862068965517 17.24137931034483
87 82.95454545454545 17.045454545454543
88 83.14606741573034 16.853932584269664
89 83.33333333333334 16.666666666666664
90 82.41758241758241 17.582417582417584
91 82.6086956521739 17.391304347826086
92 81.72043010752688 18.27956989247312
93 81.91489361702128 18.085106382978726
94 82.10526315789474 17.894736842105264
95 82.29166666666666 17.708333333333336
96 82.4742268041237 17.525773195876287
97 82.6530612244898 17.346938775510203
98 81.81818181818183 18.181818181818183
99 81.0 19.0
100 81.1881188118812 18.81188118811881
101 81.37254901960785 18.627450980392158
102 81.55339805825243 18.446601941747574
103 80.76923076923077 19.230769230769234
104 80.95238095238095 19.047619047619047
105 81.13207547169812 18.867924528301888
106 81.30841121495327 18.69158878504673
107 81.48148148148148 18.51851851851852
108 81.65137614678899 18.34862385321101
109 81.81818181818183 18.181818181818183
110 81.98198198198197 18.01801801801802
111 82.14285714285714 17.857142857142858
112 82.30088495575221 17.699115044247787
113 82.45614035087719 17.543859649122805
114 81.73913043478261 18.26086956521739
115 81.89655172413794 18.103448275862068
116 82.05128205128204 17.94871794871795
117 82.20338983050848 17.796610169491526
118 81.5126050420168 18.487394957983195
119 81.66666666666667 18.333333333333332
120 81.81818181818183 18.181818181818183
121 81.9672131147541 18.0327868852459
122 82.11382113821138 17.88617886178862
123 82.25806451612904 17.741935483870968
124 82.39999999999999 17.599999999999998
125 82.53968253968253 17.46031746031746
126 81.88976377952756 18.11023622047244
127 82.03125 17.96875
128 81.3953488372093 18.6046511627907
129 80.76923076923077 19.230769230769234
130 80.91603053435115 19.083969465648856
131 80.3030303030303 19.696969696969695
132 80.45112781954887 19.548872180451127
133 80.59701492537313 19.402985074626866
134 80.0 20.0
135 80.14705882352942 19.852941176470587
136 79.56204379562044 20.437956204379564
137 79.71014492753623 20.28985507246377
138 79.85611510791367 20.14388489208633
139 80.0 20.0
140 80.1418439716312 19.858156028368796
141 79.5774647887324 20.422535211267608
142 79.02097902097903 20.97902097902098
143 79.16666666666666 20.833333333333336
144 79.3103448275862 20.689655172413794
145 79.45205479452055 20.54794520547945
146 79.59183673469387 20.408163265306122
147 79.72972972972973 20.27027027027027
148 79.86577181208054 20.13422818791946
149 80.0 20.0
150 80.13245033112582 19.867549668874172
151 80.26315789473685 19.736842105263158
152 79.73856209150327 20.26143790849673
153 79.22077922077922 20.77922077922078
154 78.70967741935485 21.29032258064516
155 78.84615384615384 21.153846153846153
156 78.98089171974523 21.019108280254777
157 79.11392405063292 20.88607594936709
158 79.24528301886792 20.754716981132077
159 78.75 21.25
160 78.26086956521739 21.73913043478261
161 78.39506172839506 21.604938271604937
162 78.52760736196319 21.472392638036812
163 78.65853658536585 21.341463414634145
164 78.78787878787878 21.21212121212121
165 78.3132530120482 21.686746987951807
166 77.84431137724552 22.15568862275449
167 77.97619047619048 22.023809523809522
168 78.10650887573965 21.893491124260358
169 78.23529411764706 21.764705882352942
170 78.3625730994152 21.637426900584796
171 78.48837209302324 21.511627906976745
172 78.03468208092485 21.965317919075144
173 78.16091954022988 21.839080459770116
174 78.28571428571428 21.714285714285715
175 77.8409090909091 22.15909090909091
176 77.96610169491525 22.033898305084744
177 77.52808988764045 22.47191011235955
178 77.09497206703911 22.905027932960895
179 77.22222222222223 22.77777777777778
180 77.34806629834254 22.65193370165746
181 77.47252747252747 22.52747252747253
182 77.04918032786885 22.950819672131146
183 76.63043478260869 23.369565217391305
184 76.75675675675676 23.243243243243246
185 76.34408602150538 23.655913978494624
186 76.47058823529412 23.52941176470588
187 76.59574468085107 23.404255319148938
188 76.19047619047619 23.809523809523807
189 76.31578947368422 23.684210526315788
190 76.43979057591623 23.56020942408377
191 76.04166666666666 23.958333333333336
192 75.64766839378238 24.352331606217618
193 75.77319587628865 24.22680412371134
194 75.38461538461539 24.615384615384617
195 75.51020408163265 24.489795918367346
196 75.63451776649747 24.36548223350254
197 75.75757575757575 24.242424242424242
198 75.87939698492463 24.120603015075375
199 76.0 24.0
200 76.11940298507463 23.88059701492537
201 75.74257425742574 24.257425742574256
202 75.36945812807882 24.63054187192118
203 75.49019607843137 24.509803921568626
204 75.60975609756098 24.390243902439025
205 75.24271844660194 24.75728155339806
206 75.36231884057972 24.637681159420293
207 75.0 25.0
208 74.64114832535886 25.358851674641148
209 74.76190476190476 25.238095238095237
210 74.88151658767772 25.118483412322274
211 75.0 25.0
212 74.64788732394366 25.352112676056336
213 74.76635514018692 25.233644859813083
214 74.88372093023256 25.116279069767444
215 75.0 25.0
216 74.65437788018433 25.34562211981567
217 74.77064220183486 25.229357798165136
218 74.88584474885845 25.11415525114155
219 75.0 25.0
220 74.6606334841629 25.339366515837103
221 74.77477477477478 25.225225225225223
222 74.88789237668162 25.112107623318387
223 74.55357142857143 25.44642857142857
224 74.22222222222223 25.77777777777778
225 74.33628318584071 25.663716814159294
226 74.44933920704845 25.55066079295154
227 74.56140350877193 25.438596491228072
228 74.67248908296943 25.327510917030565
229 74.78260869565217 25.217391304347824
230 74.89177489177489 25.108225108225106
231 75.0 25.0
232 74.67811158798283 25.321888412017167
233 74.78632478632478 25.213675213675213
234 74.8936170212766 25.106382978723403
235 75.0 25.0
236 74.68354430379746 25.31645569620253
237 74.78991596638656 25.210084033613445
238 74.47698744769873 25.523012552301257
239 74.58333333333333 25.416666666666664
240 74.27385892116183 25.72614107883817
241 74.3801652892562 25.6198347107438
242 74.48559670781893 25.514403292181072
243 74.59016393442623 25.40983606557377
244 74.6938775510204 25.30612244897959
245 74.79674796747967 25.203252032520325
246 74.49392712550608 25.506072874493928
247 74.59677419354838 25.403225806451612
248 74.69879518072288 25.301204819277107
249 74.8 25.2
250 74.9003984063745 25.099601593625497
251 75.0 25.0
252 74.70355731225297 25.296442687747035
253 74.40944881889764 25.590551181102363
254 74.50980392156863 25.49019607843137
255 74.21875 25.78125
256 73.92996108949417 26.07003891050584
257 74.03100775193798 25.968992248062015
258 74.13127413127413 25.868725868725868
259 74.23076923076923 25.769230769230766
260 74.32950191570882 25.67049808429119
261 74.42748091603053 25.572519083969464
262 74.52471482889734 25.475285171102662
263 74.62121212121212 25.37878787878788
264 74.33962264150942 25.660377358490567
265 74.43609022556392 25.563909774436087
266 74.53183520599251 25.468164794007492
267 74.6268656716418 25.37313432835821
268 74.34944237918215 25.650557620817843
269 74.44444444444444 25.555555555555554
270 74.53874538745387 25.461254612546124
271 74.63235294117648 25.36764705882353
272 74.35897435897436 25.64102564102564
273 74.45255474452554 25.547445255474454
274 74.54545454545455 25.454545454545453
275 74.63768115942028 25.36231884057971
276 74.72924187725631 25.27075812274368
277 74.46043165467626 25.539568345323744
278 74.55197132616487 25.448028673835125
279 74.64285714285714 25.357142857142854
280 74.73309608540926 25.26690391459075
281 74.46808510638297 25.53191489361702
282 74.20494699646643 25.795053003533567
283 74.29577464788733 25.704225352112676
284 74.3859649122807 25.6140350877193
285 74.12587412587412 25.874125874125873
286 74.21602787456446 25.78397212543554
287 74.30555555555556 25.694444444444443
288 74.39446366782006 25.60553633217993
289 74.48275862068967 25.517241379310345
290 74.5704467353952 25.42955326460481
291 74.65753424657534 25.34246575342466
292 74.40273037542661 25.597269624573375
293 74.48979591836735 25.510204081632654
294 74.57627118644068 25.423728813559322
295 74.32432432432432 25.675675675675674
296 74.41077441077442 25.589225589225588
297 74.16107382550335 25.838926174496645
298 74.24749163879598 25.75250836120401
299 74.33333333333333 25.666666666666664
300 74.08637873754152 25.91362126245847
301 74.17218543046357 25.82781456953642
302 73.92739273927393 26.072607260726073
303 74.01315789473685 25.986842105263158
304 74.09836065573771 25.901639344262296
305 73.8562091503268 26.143790849673206
306 73.9413680781759 26.058631921824105
307 74.02597402597402 25.97402597402597
308 73.7864077669903 26.21359223300971
309 73.87096774193549 26.129032258064516
310 73.95498392282958 26.04501607717042
311 73.71794871794873 26.282051282051285
312 73.80191693290735 26.198083067092654
313 73.56687898089172 26.43312101910828
314 73.65079365079366 26.34920634920635
315 73.73417721518987 26.265822784810126
316 73.81703470031546 26.18296529968454
317 73.89937106918238 26.10062893081761
318 73.98119122257053 26.01880877742947
319 74.0625 25.937500000000004
320 74.14330218068535 25.85669781931464
321 73.91304347826086 26.08695652173913
322 73.68421052631578 26.31578947368421
323 73.4567901234568 26.543209876543212
324 73.53846153846155 26.461538461538463
325 73.61963190184049 26.380368098159508
326 73.70030581039755 26.299694189602445
327 73.78048780487805 26.21951219512195
328 73.86018237082067 26.13981762917933
329 73.93939393939394 26.060606060606062
330 74.01812688821752 25.981873111782477
331 74.09638554216868 25.903614457831324
332 74.17417417417418 25.825825825825827
333 73.95209580838323 26.047904191616766
334 74.02985074626865 25.970149253731346
335 74.10714285714286 25.892857142857146
336 73.88724035608308 26.112759643916917
337 73.96449704142012 26.035502958579883
338 74.04129793510324 25.958702064896755
339 74.11764705882354 25.882352941176475
340 74.19354838709677 25.806451612903224
341 74.26900584795322 25.730994152046783
342 74.34402332361516 25.65597667638484
343 74.4186046511628 25.581395348837212
344 74.4927536231884 25.507246376811594
345 74.56647398843931 25.43352601156069
346 74.63976945244957 25.360230547550433
347 74.71264367816092 25.287356321839084
348 74.78510028653295 25.214899713467048
349 74.85714285714286 25.142857142857146
350 74.92877492877493 25.071225071225072
351 75.0 25.0
352 75.07082152974505 24.929178470254957
353 75.14124293785311 24.858757062146893
354 75.21126760563381 24.788732394366196
355 75.28089887640449 24.719101123595504
356 75.35014005602241 24.649859943977592
357 75.41899441340783 24.581005586592177
358 75.4874651810585 24.512534818941504
359 75.55555555555556 24.444444444444443
360 75.62326869806094 24.37673130193906
361 75.41436464088397 24.585635359116022
362 75.48209366391184 24.517906336088156
363 75.27472527472527 24.725274725274726
364 75.34246575342466 24.65753424657534
365 75.40983606557377 24.59016393442623
366 75.20435967302453 24.795640326975477
367 75.0 25.0
368 75.06775067750678 24.932249322493224
369 74.86486486486487 25.135135135135133
370 74.93261455525607 25.067385444743934
371 75.0 25.0
372 75.06702412868633 24.932975871313673
373 75.1336898395722 24.86631016042781
374 74.93333333333332 25.066666666666666
375 75.0 25.0
376 75.06631299734748 24.93368700265252
377 75.13227513227513 24.867724867724867
378 75.19788918205805 24.80211081794195
379 75.26315789473685 24.736842105263158
380 75.32808398950131 24.671916010498688
381 75.13089005235602 24.86910994764398
382 75.19582245430809 24.804177545691903
383 75.0 25.0
384 75.06493506493507 24.935064935064936
385 75.12953367875647 24.870466321243523
386 75.1937984496124 24.8062015503876
387 75.0 25.0
388 75.06426735218508 24.93573264781491
389 74.87179487179488 25.128205128205128
390 74.93606138107417 25.063938618925828
391 75.0 25.0
392 74.80916030534351 25.190839694656486
393 74.61928934010153 25.380710659898476
394 74.68354430379746 25.31645569620253
395 74.74747474747475 25.252525252525253
396 74.81108312342569 25.188916876574307
397 74.87437185929649 25.125628140703515
398 74.93734335839599 25.062656641604008
399 75.0 25.0
400 75.06234413965088 24.93765586034913
401 75.12437810945273 24.875621890547265
402 75.18610421836229 24.81389578163772
403 75.0 25.0
404 75.06172839506173 24.938271604938272
405 75.1231527093596 24.876847290640395
406 74.93857493857494 25.061425061425062
407 75.0 25.0
408 75.06112469437653 24.938875305623473
409 75.1219512195122 24.878048780487806
410 74.93917274939173 25.060827250608277
411 75.0 25.0
412 74.818401937046 25.181598062954
413 74.63768115942028 25.36231884057971
414 74.69879518072288 25.301204819277107
415 74.75961538461539 25.240384615384613
416 74.82014388489209 25.179856115107913
417 74.64114832535886 25.358851674641148
418 74.7016706443914 25.29832935560859
419 74.76190476190476 25.238095238095237
420 74.58432304038006 25.415676959619955
421 74.64454976303317 25.355450236966824
422 74.70449172576832 25.295508274231675
423 74.52830188679245 25.471698113207548
424 74.3529411764706 25.647058823529413
425 74.4131455399061 25.586854460093893
426 74.47306791569088 25.526932084309134
427 74.29906542056075 25.70093457943925
428 74.12587412587412 25.874125874125873
429 74.18604651162791 25.813953488372093
430 74.24593967517401 25.754060324825982
431 74.07407407407408 25.925925925925924
432 74.13394919168591 25.86605080831409
433 74.19354838709677 25.806451612903224
434 74.25287356321839 25.74712643678161
435 74.31192660550458 25.688073394495415
436 74.37070938215103 25.62929061784897
437 74.42922374429224 25.570776255707763
438 74.4874715261959 25.512528473804103
439 74.31818181818181 25.681818181818183
440 74.37641723356009 25.623582766439913
441 74.2081447963801 25.791855203619914
442 74.2663656884876 25.733634311512414
443 74.32432432432432 25.675675675675674
444 74.38202247191012 25.617977528089884
445 74.2152466367713 25.784753363228702
446 74.27293064876957 25.727069351230426
447 74.33035714285714 25.669642857142854
448 74.16481069042317 25.83518930957684
449 74.22222222222223 25.77777777777778
450 74.27937915742794 25.72062084257206
451 74.33628318584071 25.663716814159294
452 74.39293598233996 25.607064017660043
453 74.44933920704845 25.55066079295154
454 74.28571428571429 25.71428571428571
455 74.3421052631579 25.657894736842106
456 74.39824945295405 25.601750547045953
457 74.235807860262 25.76419213973799
458 74.29193899782135 25.70806100217865
459 74.1304347826087 25.869565217391305
460 74.18655097613883 25.813449023861175
461 74.02597402597402 25.97402597402597
462 74.08207343412528 25.917926565874733
463 74.13793103448276 25.862068965517242
464 74.19354838709677 25.806451612903224
465 74.2489270386266 25.75107296137339
466 74.30406852248393 25.69593147751606
467 74.35897435897436 25.64102564102564
468 74.4136460554371 25.5863539445629
469 74.46808510638297 25.53191489361702
470 74.52229299363057 25.477707006369428
471 74.57627118644068 25.423728813559322
472 74.63002114164905 25.36997885835095
473 74.68354430379746 25.31645569620253
474 74.73684210526315 25.263157894736842
475 74.78991596638656 25.210084033613445
476 74.84276729559748 25.157232704402517
477 74.89539748953975 25.10460251046025
478 74.94780793319416 25.052192066805844
479 74.79166666666667 25.208333333333332
480 74.84407484407485 25.155925155925157
481 74.89626556016597 25.103734439834025
482 74.94824016563147 25.051759834368532
483 75.0 25.0
484 75.05154639175258 24.948453608247423
485 75.1028806584362 24.897119341563787
486 75.15400410677618 24.84599589322382
487 75.20491803278688 24.795081967213115
488 75.25562372188139 24.74437627811861
489 75.3061224489796 24.693877551020407
490 75.35641547861506 24.643584521384927
491 75.40650406504065 24.59349593495935
492 75.25354969574036 24.746450304259636
493 75.30364372469636 24.696356275303643
494 75.35353535353535 24.646464646464647
495 75.40322580645162 24.596774193548388
496 75.25150905432596 24.748490945674046
497 75.30120481927712 24.69879518072289
498 75.1503006012024 24.849699398797593
499 75.2 24.8
500 75.249500998004 24.75049900199601
501 75.2988047808765 24.701195219123505
502 75.3479125248509 24.652087475149106
503 75.39682539682539 24.6031746031746
504 75.44554455445545 24.554455445544555
505 75.29644268774703 24.703557312252965
506 75.34516765285996 24.65483234714004
507 75.19685039370079 24.803149606299215
508 75.24557956777997 24.75442043222004
509 75.29411764705883 24.705882352941178
510 75.34246575342466 24.65753424657534
511 75.390625 24.609375
512 75.24366471734892 24.756335282651072
513 75.29182879377431 24.708171206225682
514 75.33980582524272 24.660194174757283
515 75.3875968992248 24.612403100775193
516 75.43520309477756 24.564796905222437
517 75.4826254826255 24.517374517374517
518 75.52986512524085 24.470134874759154
519 75.57692307692308 24.423076923076923
520 75.62380038387715 24.37619961612284
521 75.47892720306514 24.521072796934863
522 75.52581261950286 24.47418738049713
523 75.57251908396947 24.427480916030532
524 75.61904761904762 24.38095238095238
525 75.66539923954373 24.334600760456272
526 75.52182163187857 24.47817836812144
527 75.56818181818183 24.431818181818183
528 75.61436672967864 24.38563327032136
529 75.66037735849058 24.339622641509433
530 75.70621468926554 24.293785310734464
531 75.75187969924812 24.24812030075188
532 75.79737335834896 24.202626641651033
533 75.84269662921348 24.15730337078652
534 75.88785046728972 24.11214953271028
535 75.74626865671642 24.253731343283583
536 75.60521415270019 24.39478584729981
537 75.65055762081785 24.349442379182157
538 75.69573283858998 24.304267161410017
539 75.74074074074075 24.25925925925926
540 75.78558225508318 24.214417744916823
541 75.83025830258303 24.169741697416974
542 75.87476979742172 24.12523020257827
543 75.73529411764706 24.264705882352942
544 75.77981651376146 24.220183486238533
545 75.64102564102564 24.358974358974358
546 75.50274223034735 24.49725776965265
547 75.54744525547446 24.45255474452555
548 75.40983606557377 24.59016393442623
549 75.45454545454545 24.545454545454547
550 75.49909255898368 24.500907441016334
551 75.36231884057972 24.637681159420293
552 75.40687160940325 24.593128390596743
553 75.45126353790613 24.548736462093864
554 75.49549549549549 24.504504504504503
555 75.53956834532374 24.46043165467626
556 75.58348294434471 24.416517055655294
557 75.44802867383513 24.551971326164875
558 75.49194991055455 24.508050089445437
559 75.53571428571428 24.46428571428571
560 75.40106951871658 24.598930481283425
561 75.44483985765125 24.555160142348754
562 75.48845470692717 24.51154529307282
563 75.53191489361703 24.46808510638298
564 75.57522123893806 24.424778761061948
565 75.61837455830388 24.381625441696116
566 75.66137566137566 24.33862433862434
567 75.70422535211267 24.295774647887324
568 75.7469244288225 24.253075571177504
569 75.78947368421053 24.210526315789473
570 75.83187390542906 24.168126094570926
571 75.87412587412588 24.125874125874127
572 75.91623036649214 24.083769633507853
573 75.9581881533101 24.041811846689896
574 75.82608695652175 24.173913043478258
575 75.86805555555556 24.131944444444446
576 75.736568457539 24.263431542461007
577 75.60553633217994 24.39446366782007
578 75.64766839378238 24.352331606217618
579 75.51724137931033 24.482758620689655
580 75.5593803786575 24.440619621342513
581 75.60137457044674 24.398625429553263
582 75.64322469982847 24.356775300171527
583 75.68493150684932 24.315068493150687
584 75.72649572649573 24.273504273504273
585 75.59726962457339 24.40273037542662
586 75.46848381601363 24.531516183986373
587 75.51020408163265 24.489795918367346
588 75.38200339558574 24.61799660441426
589 75.42372881355932 24.576271186440678
590 75.29610829103216 24.703891708967852
591 75.33783783783784 24.66216216216216
592 75.37942664418212 24.620573355817875
593 75.42087542087542 24.579124579124578
594 75.29411764705883 24.705882352941178
595 75.16778523489933 24.832214765100673
596 75.20938023450586 24.79061976549414
597 75.25083612040135 24.74916387959866
598 75.29215358931552 24.707846410684475
599 75.33333333333333 24.666666666666668
600 75.37437603993344 24.625623960066555
601 75.41528239202658 24.58471760797342
602 75.29021558872306 24.70978441127695
603 75.16556291390728 24.834437086092713
604 75.20661157024794 24.793388429752067
605 75.24752475247524 24.752475247524753
606 75.12355848434926 24.87644151565074
607 75.16447368421053 24.835526315789476
608 75.20525451559934 24.794745484400657
609 75.08196721311475 24.91803278688525
610 75.12274959083469 24.877250409165303
611 75.16339869281046 24.836601307189543
612 75.20391517128874 24.79608482871126
613 75.2442996742671 24.7557003257329
614 75.28455284552845 24.715447154471544
615 75.32467532467533 24.675324675324674
616 75.3646677471637 24.635332252836303
617 75.40453074433657 24.59546925566343
618 75.44426494345718 24.55573505654281
619 75.48387096774194 24.516129032258064
620 75.52334943639292 24.476650563607087
621 75.56270096463022 24.437299035369776
622 75.60192616372392 24.398073836276083
623 75.48076923076923 24.519230769230766
624 75.52 24.48
625 75.39936102236422 24.600638977635782
626 75.43859649122807 24.561403508771928
627 75.47770700636943 24.522292993630572
628 75.516693163752 24.483306836248012
629 75.55555555555556 24.444444444444443
630 75.59429477020603 24.405705229793977
631 75.63291139240506 24.367088607594937
632 75.67140600315956 24.328593996840443
633 75.70977917981072 24.290220820189273
634 75.74803149606299 24.251968503937007
635 75.78616352201259 24.21383647798742
636 75.82417582417582 24.175824175824175
637 75.86206896551724 24.137931034482758
638 75.8998435054773 24.100156494522693
639 75.78125 24.21875
640 75.81903276131045 24.180967238689547
641 75.85669781931465 24.143302180685357
642 75.89424572317263 24.10575427682737
643 75.93167701863354 24.06832298136646
644 75.96899224806202 24.031007751937985
645 76.0061919504644 23.993808049535602
646 76.04327666151468 23.956723338485318
647 76.08024691358025 23.919753086419753
648 75.96302003081664 24.03697996918336
649 75.84615384615384 24.153846153846153
650 75.88325652841782 24.11674347158218
651 75.920245398773 24.079754601226995
652 75.95712098009189 24.042879019908117
653 75.84097859327217 24.159021406727827
654 75.87786259541984 24.12213740458015
655 75.91463414634147 24.085365853658537
656 75.95129375951294 24.04870624048706
657 75.83586626139818 24.164133738601823
658 75.87253414264038 24.12746585735964
659 75.9090909090909 24.09090909090909
660 75.94553706505295 24.05446293494705
661 75.98187311178248 24.018126888217523
662 76.01809954751131 23.981900452488688
663 76.05421686746988 23.94578313253012
664 76.09022556390977 23.909774436090224
665 75.97597597597597 24.024024024024023
666 76.01199400299849 23.988005997001498
667 76.04790419161677 23.952095808383234
668 76.08370702541106 23.916292974588938
669 76.11940298507463 23.88059701492537
670 76.00596125186289 23.994038748137108
671 75.89285714285714 24.107142857142858
672 75.92867756315007 24.071322436849925
673 75.96439169139467 24.03560830860534
674 75.85185185185185 24.14814814814815
675 75.88757396449705 24.11242603550296
676 75.9231905465288 24.076809453471196
677 75.81120943952803 24.188790560471976
678 75.84683357879234 24.153166421207658
679 75.88235294117646 24.11764705882353
680 75.91776798825258 24.082232011747433
681 75.95307917888563 24.04692082111437
682 75.9882869692533 24.011713030746705
683 76.0233918128655 23.976608187134502
684 76.05839416058394 23.94160583941606
685 75.94752186588921 24.05247813411079
686 75.9825327510917 24.017467248908297
687 76.01744186046511 23.982558139534884
688 75.90711175616835 24.092888243831638
689 75.79710144927536 24.20289855072464
690 75.83212735166425 24.167872648335745
691 75.86705202312139 24.13294797687861
692 75.9018759018759 24.0981240981241
693 75.79250720461094 24.207492795389047
694 75.8273381294964 24.172661870503596
695 75.7183908045977 24.281609195402297
696 75.60975609756098 24.390243902439025
697 75.64469914040114 24.355300859598856
698 75.67954220314735 24.320457796852647
699 75.71428571428571 24.285714285714285
700 75.60627674750357 24.393723252496432
701 75.64102564102564 24.358974358974358
702 75.53342816500711 24.466571834992887
703 75.56818181818183 24.431818181818183
704 75.60283687943262 24.397163120567374
705 75.63739376770539 24.362606232294617
706 75.67185289957567 24.328147100424328
707 75.70621468926554 24.293785310734464
708 75.74047954866009 24.259520451339917
709 75.77464788732394 24.225352112676056
710 75.80872011251758 24.19127988748242
711 75.84269662921348 24.15730337078652
712 75.8765778401122 24.1234221598878
713 75.7703081232493 24.2296918767507
714 75.8041958041958 24.195804195804197
715 75.83798882681563 24.162011173184357
716 75.87168758716875 24.12831241283124
717 75.90529247910864 24.094707520891365
718 75.93880389429764 24.061196105702365
719 75.97222222222221 24.02777777777778
720 76.00554785020805 23.994452149791957
721 76.0387811634349 23.961218836565095
722 76.07192254495159 23.92807745504841
723 76.10497237569061 23.895027624309392
724 76.0 24.0
725 75.89531680440771 24.104683195592287
726 75.79092159559835 24.20907840440165
727 75.82417582417582 24.175824175824175
728 75.85733882030178 24.142661179698216
729 75.89041095890411 24.10958904109589
730 75.9233926128591 24.076607387140903
731 75.81967213114754 24.18032786885246
732 75.85266030013642 24.147339699863572
733 75.74931880108991 24.250681198910083
734 75.78231292517007 24.217687074829932
735 75.67934782608695 24.320652173913043
736 75.57666214382633 24.423337856173678
737 75.60975609756098 24.390243902439025
738 75.64276048714478 24.357239512855212
739 75.67567567567568 24.324324324324326
740 75.7085020242915 24.291497975708502
741 75.74123989218329 24.258760107816713
742 75.77388963660835 24.226110363391655
743 75.80645161290323 24.193548387096776
744 75.83892617449665 24.161073825503358
745 75.87131367292224 24.128686327077748
746 75.90361445783132 24.096385542168676
747 75.93582887700535 24.06417112299465
748 75.9679572763685 24.03204272363151
749 76.0 24.0
750 76.03195739014647 23.96804260985353
751 75.93085106382979 24.069148936170212
752 75.96281540504648 24.03718459495352
753 75.86206896551724 24.137931034482758
754 75.89403973509934 24.10596026490066
755 75.92592592592592 24.074074074074073
756 75.82562747688243 24.17437252311757
757 75.85751978891821 24.142480211081793
758 75.8893280632411 24.110671936758894
759 75.92105263157895 24.07894736842105
760 75.9526938239159 24.0473061760841
761 75.98425196850394 24.015748031496063
762 75.88466579292268 24.11533420707733
763 75.91623036649214 24.083769633507853
764 75.81699346405229 24.18300653594771
765 75.8485639686684 24.151436031331595
766 75.7496740547588 24.2503259452412
767 75.78125 24.21875
768 75.81274382314695 24.187256176853055
769 75.84415584415585 24.155844155844157
770 75.74578469520104 24.25421530479896
771 75.77720207253887 24.22279792746114
772 75.80853816300129 24.191461836998705
773 75.83979328165374 24.160206718346252
774 75.74193548387098 24.258064516129032
775 75.77319587628865 24.22680412371134
776 75.67567567567568 24.324324324324326
777 75.57840616966581 24.42159383033419
778 75.4813863928113 24.5186136071887
779 75.51282051282051 24.487179487179485
780 75.41613316261203 24.583866837387962
781 75.44757033248082 24.55242966751918
782 75.47892720306514 24.521072796934863
783 75.51020408163265 24.489795918367346
784 75.54140127388536 24.45859872611465
785 75.44529262086515 24.55470737913486
786 75.47649301143584 24.52350698856417
787 75.38071065989847 24.61928934010152
788 75.41191381495564 24.58808618504436
789 75.44303797468355 24.556962025316455
790 75.47408343868521 24.52591656131479
791 75.37878787878788 24.62121212121212
792 75.40983606557377 24.59016393442623
793 75.44080604534005 24.55919395465995
794 75.47169811320755 24.528301886792452
795 75.50251256281408 24.49748743718593
796 75.4077791718946 24.592220828105397
797 75.43859649122807 24.561403508771928
798 75.3441802252816 24.6558197747184
799 75.375 24.625
800 75.40574282147315 24.594257178526842
801 75.43640897755611 24.56359102244389
802 75.46699875466999 24.533001245330013
803 75.49751243781094 24.502487562189053
804 75.527950310559 24.472049689440993
805 75.55831265508685 24.441687344913152
806 75.58859975216853 24.411400247831473
807 75.61881188118812 24.38118811881188
808 75.64894932014833 24.351050679851667
809 75.67901234567901 24.320987654320987
810 75.70900123304563 24.290998766954377
811 75.61576354679804 24.38423645320197
812 75.52275522755227 24.477244772447722
813 75.55282555282555 24.447174447174447
814 75.58282208588956 24.41717791411043
815 75.61274509803921 24.387254901960784
816 75.64259485924113 24.35740514075887
817 75.67237163814181 24.327628361858192
818 75.7020757020757 24.297924297924297
819 75.73170731707317 24.268292682926827
820 75.76126674786845 24.238733252131546
821 75.79075425790755 24.20924574209246
822 75.82017010935601 24.179829890643987
823 75.72815533980582 24.271844660194176
824 75.75757575757575 24.242424242424242
825 75.78692493946731 24.213075060532688
826 75.81620314389359 24.18379685610641
827 75.84541062801932 24.154589371980677
828 75.8745476477684 24.125452352231605
829 75.90361445783132 24.096385542168676
830 75.93261131167269 24.067388688327316
831 75.96153846153845 24.03846153846154
832 75.87034813925571 24.129651860744296
833 75.89928057553958 24.100719424460433
834 75.92814371257485 24.07185628742515
835 75.95693779904306 24.04306220095694
836 75.98566308243727 24.014336917562723
837 75.89498806682577 24.105011933174225
838 75.92371871275327 24.076281287246722
839 75.95238095238095 24.047619047619047
840 75.98097502972652 24.019024970273485
841 76.00950118764845 23.990498812351543
842 75.91933570581257 24.080664294187425
843 75.9478672985782 24.0521327014218
844 75.97633136094674 24.023668639053255
845 76.00472813238771 23.995271867612296
846 76.03305785123968 23.96694214876033
847 76.06132075471697 23.93867924528302
848 76.08951707891637 23.910482921083627
849 76.11764705882354 23.88235294117647
850 76.02820211515863 23.971797884841365
851 76.05633802816901 23.943661971830984
852 75.96717467760844 24.03282532239156
853 75.99531615925058 24.004683840749415
854 75.90643274853801 24.09356725146199
855 75.93457943925233 24.065420560747665
856 75.96266044340723 24.037339556592766
857 75.990675990676 24.00932400932401
858 76.0186263096624 23.981373690337602
859 76.04651162790698 23.953488372093023
860 76.07433217189315 23.925667828106853
861 76.10208816705337 23.897911832946637
862 76.1297798377752 23.870220162224797
863 76.1574074074074 23.84259259259259
864 76.18497109826589 23.815028901734102
865 76.09699769053118 23.90300230946882
866 76.12456747404845 23.875432525951556
867 76.15207373271889 23.847926267281107
868 76.17951668584581 23.8204833141542
869 76.20689655172413 23.79310344827586
870 76.11940298507463 23.88059701492537
871 76.14678899082568 23.853211009174313
872 76.17411225658648 23.825887743413514
873 76.20137299771167 23.79862700228833
874 76.22857142857143 23.771428571428572
875 76.25570776255708 23.74429223744292
876 76.28278221208666 23.71721778791334
877 76.30979498861048 23.690205011389523
878 76.3367463026166 23.66325369738339
879 76.36363636363637 23.636363636363637
880 76.39046538024972 23.609534619750285
881 76.41723356009071 23.582766439909296
882 76.44394110985277 23.556058890147224
883 76.47058823529412 23.52941176470588
884 76.49717514124293 23.502824858757062
885 76.52370203160271 23.47629796839729
886 76.55016910935738 23.449830890642616
887 76.57657657657657 23.423423423423422
888 76.6029246344207 23.397075365579305
889 76.62921348314606 23.370786516853933
890 76.65544332210999 23.34455667789001
891 76.68161434977578 23.318385650224215
892 76.70772676371782 23.292273236282195
893 76.7337807606264 23.2662192393736
894 76.75977653631286 23.24022346368715
895 76.78571428571429 23.214285714285715
896 76.81159420289855 23.18840579710145
897 76.83741648106904 23.16258351893096
898 76.86318131256952 23.136818687430477
899 76.88888888888889 23.11111111111111
900 76.91453940066593 23.085460599334073
901 76.94013303769401 23.059866962305986
902 76.9656699889258 23.034330011074196
903 76.99115044247787 23.008849557522122
904 77.01657458563535 22.983425414364643
905 77.04194260485652 22.958057395143488
906 77.06725468577729 22.932745314222714
907 77.09251101321586 22.90748898678414
908 77.11771177117713 22.882288228822883
909 77.03296703296704 22.967032967032967
910 77.05817782656422 22.941822173435785
911 77.08333333333334 22.916666666666664
912 77.10843373493977 22.89156626506024
913 77.02407002188184 22.975929978118163
914 77.04918032786885 22.950819672131146
915 76.9650655021834 23.034934497816593
916 76.99018538713194 23.00981461286805
917 77.01525054466231 22.984749455337692
918 77.04026115342764 22.95973884657236
919 77.06521739130436 22.934782608695652
920 77.0901194353963 22.90988056460369
921 77.11496746203905 22.885032537960953
922 77.13976164680389 22.8602383531961
923 77.05627705627705 22.943722943722943
924 77.08108108108108 22.91891891891892
925 76.99784017278618 23.002159827213823
926 77.02265372168284 22.97734627831715
927 77.04741379310344 22.95258620689655
928 77.07212055974165 22.92787944025834
929 77.09677419354838 22.903225806451612
930 77.12137486573577 22.878625134264233
931 77.14592274678111 22.854077253218886
932 77.17041800643086 22.829581993569132
933 77.19486081370451 22.805139186295502
934 77.2192513368984 22.780748663101605
935 77.24358974358975 22.756410256410255
936 77.26787620064034 22.73212379935966
937 77.29211087420043 22.707889125799575
938 77.31629392971246 22.683706070287542
939 77.34042553191489 22.659574468085104
940 77.36450584484591 22.635494155154092
941 77.38853503184714 22.611464968152866
942 77.30646871686108 22.693531283138917
943 77.22457627118644 22.77542372881356
944 77.24867724867724 22.75132275132275
945 77.27272727272727 22.727272727272727
946 77.29672650475185 22.70327349524815
947 77.32067510548524 22.679324894514767
948 77.3445732349842 22.655426765015807
949 77.36842105263158 22.63157894736842
950 77.39221871713985 22.60778128286015
951 77.31092436974791 22.689075630252102
952 77.22980062959076 22.770199370409234
953 77.25366876310272 22.746331236897273
954 77.27748691099477 22.722513089005236
955 77.30125523012552 22.698744769874477
956 77.32497387669801 22.675026123301986
957 77.34864300626305 22.65135699373695
958 77.37226277372264 22.62773722627737
959 77.29166666666667 22.708333333333332
960 77.21123829344432 22.788761706555672
961 77.13097713097713 22.86902286902287
962 77.15472481827622 22.84527518172378
963 77.17842323651453 22.821576763485478
964 77.2020725388601 22.797927461139896
965 77.22567287784679 22.77432712215321
966 77.24922440537746 22.750775594622542
967 77.27272727272727 22.727272727272727
968 77.19298245614034 22.807017543859647
969 77.21649484536083 22.783505154639176
970 77.2399588053553 22.760041194644696
971 77.2633744855967 22.73662551440329
972 77.28674203494347 22.713257965056528
973 77.31006160164272 22.68993839835729
974 77.33333333333333 22.666666666666664
975 77.25409836065575 22.74590163934426
976 77.27737973387923 22.722620266120778
977 77.19836400817995 22.801635991820042
978 77.22165474974464 22.778345250255363
979 77.14285714285715 22.857142857142858
980 77.06422018348624 22.93577981651376
981 77.08757637474541 22.912423625254583
982 77.11088504577823 22.88911495422177
983 77.13414634146342 22.865853658536587
984 77.05583756345177 22.944162436548226
985 77.079107505071 22.920892494929006
986 77.10233029381965 22.897669706180345
987 77.1255060728745 22.874493927125506
988 77.14863498483317 22.851365015166834
989 77.07070707070707 22.92929292929293
990 76.99293642785065 23.007063572149345
991 77.01612903225806 22.983870967741936
992 76.9385699899295 23.061430010070495
993 76.96177062374245 23.038229376257547
994 76.98492462311557 23.015075376884422
995 77.00803212851406 22.991967871485944
996 76.9307923771314 23.069207622868607
997 76.85370741482967 23.146292585170343
998 76.87687687687688 23.123123123123122
999 76.9 23.1
import numpy as np
import pandas as pd
# produce a random pair of integers representing (number of doors,door of car)
x = np.random.randint(low=1, high=4+1, size=(1,2))
x
# adapted from Nick Heitzman's work on LinkedIn:
# https://www.linkedin.com/pulse/simulating-monty-hall-problem-python-nick-heitzman
# used by permission of the author
def monty_hall():
[[chosen_door, winner]] = np.random.randint(low=1,high=4+1,size=(1,2))
options = [1,2,3,4]
if chosen_door == winner:
options.remove(chosen_door)
open_door = np.random.choice(options)
switch_door = options.remove(open_door)
else:
options.remove(chosen_door)
options.remove(winner)
open_door = options
switch_door = winner
# 1 = win, 0 = lose
if switch_door == winner:
switch = 1.
non_switch = 0.
else:
switch = 0.
non_switch = 1.
return switch, non_switch
# simulate playing the game numerous times
def simulation():
switch_output = []
no_switch_output = []
# run the simulation 1000 times
for x in range(1000):
switch, no_switch = monty_hall()
switch_output.append(switch)
no_switch_output.append(no_switch)
return switch_output, no_switch_output
# run simulation
switch, no_switch = simulation()
print('The probability of winning if you switch doors is: %s' % str(sum(switch) / len(switch)))
print('The probability of winning if you keep door A is: %s' % str(sum(no_switch) / len(no_switch)))
# produce a table of results
switch, no_switch = simulation()
df = pd.DataFrame(np.column_stack((switch,no_switch)) , columns=['win_switch', 'lose_switch'])
df['switch_pct'] = pd.expanding_mean(df['win_switch'], min_periods=1)
df['no_switch_pct'] = pd.expanding_mean(df['lose_switch'], min_periods=1)
df = df[['switch_pct', 'no_switch_pct']] * 100
df.columns = ['switch doors', 'do not switch doors']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment