using System; using System.Collections; namespace ConsoleApplication1 { /// /// Showing the stats for the Monty Hall problem. /// class MontyHall { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { int games = (args.Length > 0 ? Convert.ToInt32(args[0]) : 10000); Random r = new Random(); int correctWhenStick = 0; int correctWhenChange = 0; for (int i = 0; i < games; i++) { int rightAnswer = r.Next(3); int initialGuess = r.Next(3); if (initialGuess != rightAnswer) { // your initial guess is wrong // the other booby prize door is open // so to change is to get the prize. correctWhenChange++; } else if (initialGuess == rightAnswer) { // you got the prize right first time. // so to stick is to get the prize. correctWhenStick++; } } Console.WriteLine("Over " + games + " games, changing wins " + correctWhenChange + " times and sticking wins " + correctWhenStick + " times."); } } }