Created
March 6, 2012 16:03
-
-
Save shimondoodkin/1987046 to your computer and use it in GitHub Desktop.
in game theory there is an idea about the old tv show of 3 doors where you choose a door and then the showman says there is nothing behind that door you did not choose. would you like to switch? the idea saya that if you switch you should have more chance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var doors=7; | |
function offerdoors() | |
{ | |
if(doors<3) return "error"; | |
var arr=[];for(var d=0;d<doors;d++)arr[d]=0;// fill the rage | |
arr[Math.floor(Math.random()*3)]=1; | |
choose(arr) | |
} | |
function whereno(arr,choice) | |
{ | |
while(true) | |
{ | |
var randomtoremove=Math.floor(Math.random()*doors); | |
if(randomtoremove==choice) continue; | |
if(arr[randomtoremove]==1) continue; | |
return randomtoremove; | |
} | |
} | |
function choose(arr) | |
{ | |
var choice=Math.floor(Math.random()*doors); | |
var whereisno=whereno(arr,choice) | |
var toswitch=Math.floor(Math.random()*2); | |
if(toswitch==1) | |
{ | |
while(true) | |
{ | |
var newchoice=Math.floor(Math.random()*doors); | |
if(newchoice==whereisno)continue; | |
if(newchoice==choice)continue; | |
break; | |
} | |
log_result(toswitch,arr[newchoice]) | |
} | |
else | |
log_result(toswitch,arr[choice]) | |
} | |
var results=[[],[]] | |
function log_result(toswitch,x) | |
{ | |
results[toswitch].push(x); | |
} | |
var tests=1000 | |
while(results[0].length<tests||results[1].length<tests) | |
offerdoors() | |
function round(num, dec) {return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);} | |
console.log("percent of success") | |
var sum,toswitch; | |
sum=0; | |
toswitch=1; | |
results[toswitch].splice(tests);; | |
results[toswitch].forEach(function(c){sum+=c}) | |
var avg=sum/results[toswitch].length; | |
console.log(results[toswitch].length+" tests"," to switch",round(avg*100,2)+"%","a chance of "+round(avg*doors,2)+" in "+doors); | |
sum=0; | |
toswitch=0; | |
results[toswitch].splice(tests);; | |
results[toswitch].forEach(function(c){sum+=c}) | |
var avg=sum/results[toswitch].length; | |
console.log(results[toswitch].length+" tests","not switch",round(avg*100,2)+"%","a chance of "+round(avg*doors,2)+" in "+doors); |
I guess the higher rate is because you choose one from two, not from 3.
a choice of a one from two really makes a difference
if you switch. you get some chance points for free as the removed chance.
as 1/[num choices], when the chance is 1/3, you get another 1/3 for free.
but in numbers larger then 5 it halps a very little.
looks like a chance of 50% that it will halp a about 10% in larger numbers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
percent of success
1000 tests to switch 0.3% a chance of 0.3 in 100
1000 tests not switch 0.7% a chance of 0.7 in 100
now this is surprising the success supposed to be 0.01; but it is larger.