Last active
August 29, 2015 14:01
-
-
Save IanWold/cc290932da3d238b0e40 to your computer and use it in GitHub Desktop.
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; | |
using C = System.Console; | |
namespace MontyHall | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] Doors = new int[3]; | |
const int times = 1000000; | |
Random rnd = new Random(); | |
int totalWins = 0; | |
//Loop times times, not switching | |
for (int i = 0; i < times; i++) | |
{ | |
//Construct new doors, populate one with 1 | |
Doors = new int[3] { 0, 0, 0 }; | |
Doors[rnd.Next(1, 4) - 1] = 1; | |
//Guess any random door | |
totalWins += Doors[rnd.Next(1, 4) - 1]; | |
} | |
C.WriteLine("No Switch: {0} / {1}", totalWins, times); | |
C.WriteLine("Yes Switch: {0} / {1}", (times - totalWins), times); | |
C.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment