using MicrosoftResearch.R2Lib; using MicrosoftResearch.R2Lib.Distributions; class MontyHall { public Tuple Infer() { double[] probabilities = new double[] { 1.0/3, 1.0/3, 1.0/3 }; // Set up the game. int carDoorNum = Categorical.Sample(probabilities); // Contestant picks a door. int chosenDoorNum = Categorical.Sample(probabilities); // Host picks a door. int[] possibleOpenDoors; int openedDoorNum = -1; int i, j; if (carDoorNum == chosenDoorNum) { possibleOpenDoors = new int[2]; j = 0; for (i = 0; i < 3; ++i) { if (i != carDoorNum) { possibleOpenDoors[j] = i; ++j; } } j = Categorical.Sample(new double[] { 0.5, 0.5 }); openedDoorNum = possibleOpenDoors[j]; } else { for (i = 0; i < 3; ++i) { if ((i != carDoorNum) && (i != chosenDoorNum)) { openedDoorNum = i; } } } bool chosenDoorContainsCar = false, otherDoorContainsCar = false; // Does contestant win if s/he doesn't switch? chosenDoorContainsCar = (chosenDoorNum == carDoorNum); // Does contestant win if s/he switches? for (i = 0; i < 3; ++i) { if ((i != chosenDoorNum) && (i != openedDoorNum)) { otherDoorContainsCar = (i == carDoorNum); } } return new Tuple(chosenDoorContainsCar, otherDoorContainsCar); } }
People
Aditya Nori
Partner Research Manager
Sriram Rajamani
Corporate Vice President, Microsoft Research