Skip to content

Instantly share code, notes, and snippets.

@IanWold
Last active August 29, 2015 14:01
Show Gist options
  • Save IanWold/cc290932da3d238b0e40 to your computer and use it in GitHub Desktop.
Save IanWold/cc290932da3d238b0e40 to your computer and use it in GitHub Desktop.
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