Created
February 15, 2016 13:45
-
-
Save XDRosenheim/407e5acc54ba66eb4131 to your computer and use it in GitHub Desktop.
Is it better to change door at the Monty Hall problem?
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
using System; | |
namespace MontyHall { | |
internal class Program { | |
private static void Main() { | |
var rnd = new Random(); | |
bool[] doors = { false, false, false }; | |
const int iterations = 10000000; | |
var counter = 0; | |
var winsOnChange = 0; | |
var winsOnStaying = 0; | |
while(counter < iterations) { | |
doors[0] = false; | |
doors[1] = false; | |
doors[2] = false; | |
doors[rnd.Next( 1, 4 ) - 1] = true; | |
if(doors[rnd.Next( 1, 4 ) - 1]) { | |
winsOnStaying++; | |
} | |
counter++; | |
} | |
counter = 0; | |
while(counter < iterations) { | |
doors[0] = false; | |
doors[1] = false; | |
doors[2] = false; | |
doors[rnd.Next( 1, 4 ) - 1] = true; | |
if(!doors[rnd.Next( 1, 4 ) - 1]) { | |
winsOnChange++; | |
} | |
counter++; | |
} | |
Console.WriteLine( "Change door: \t" + winsOnChange + " / " + iterations ); | |
Console.WriteLine( "Same door: \t" + winsOnStaying + " / " + iterations ); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment