using System; class MontyHall { private static Random rnd = new Random(); public static int OpenDoor(int a, int b, int winning) { if (winning == a) { return b; } if (winning == b) { return a; } double choice = rnd.NextDouble(); if (choice < 0.5) { return a; } else { return b; } } public static void Main() { int total = 1000; int win = 0; for (int i = 0; i < total; i++) { int winningDoor = (int)(rnd.NextDouble() * 3.0) % 3 + 1; int choice = (int)(rnd.NextDouble() * 3.0) % 3 + 1; int open; if (choice == 1) { open = OpenDoor(2, 3, winningDoor); } else if (choice == 2) { open = OpenDoor(1, 3, winningDoor); } else { //if (choice == 3) { open = OpenDoor(2, 1, winningDoor); } Console.WriteLine("Winning door: {0}\t Player's choice: {1}\tOpen: {2}", winningDoor, choice, open); if (choice == winningDoor) { win++; } } Console.WriteLine("Total: {0}\tWin by switching: {1}\tWin by staying: {2}", total, total - win, win); } };