Skip to content

Instantly share code, notes, and snippets.

@johnrigler
Last active December 16, 2023 17:55
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 johnrigler/6a4fb2dffed8a3b0b790d2aa65b440a3 to your computer and use it in GitHub Desktop.
Save johnrigler/6a4fb2dffed8a3b0b790d2aa65b440a3 to your computer and use it in GitHub Desktop.
Monty Hall problem solved (this is stupid)
monty = function()
{
/*
Assumptions:
1. The host will always give you a second choice.
2. The host will never open the door with the prize
because that would end the mystery.
Hypothesis:
Most people are right and this is math foolishness. This is not
the prisoner's dilemma. This is liar's paradox which is solved
by asking the liar what the truth-teller would say and doing
the opposite.
Parameters:
The monty function takes a number, either 2 or 3 and
returns [ 0,1,2 ] or [ 0,1 ]. You
always choose door 2 and the host always opens door 0
or 1. Randomly chosing a different door doesn't change
the outcome over time.
*/
monty_ = function(x) { return Math.floor(Math.random(1) * x); }
win = 0;
lie = 0;
for( x = 0; x < 1000000; x++) {
door = monty_(3);
lie = monty_(2);
if(door == 2) {
if(lie)win++; }
else
if(door == 1)
if(lie)win++;
}
console.log( win / 10000 );
/* By running monty_ repeatedly with "3", we obviously get
a 33% success rate across the million executions. We
would get the same with a trillion or a zillion
zillion. Making the number larger is pointless. Running
monty_ with "2" a million, billion, or trillion times would also
give us a 50% success rate. No need to do this. So the
only thing we can do is run monty(2) against the
results of monty(3) and see if the win rate changes. With
this version, we still get the same odds. */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment