%car-goat-goat %Matthew Miller %10/8/2021 %select number of iterations loopLimit=1e7; %create variables %After seeing the Omnicient Host open a door, the contestant should stay OHCorrectToStay = 0; %After seeing the Omnicient Host open a door, the contestant should switch OHCorrectToSwitch = 0; %The contestant guessed right before seeing the hosts door guessRight = 0; %The contestant guessed right at first guessWrong = 0; for n=1:loopLimit %random number to assign goats and car behind doors a = rand(1); %random number to assign contestant guesses b = rand(1); %random number to assign host guesses c = rand(1); %cargoatgoat assignment if a < 1/3 doors = ([1 0 0]); elseif a > 1/3 && a < 2/3 doors = ([0 1 0]); elseif a > 2/3 doors = ([0 0 1]); end %Constestant with Omnicient Host (OHContestant) guesses door if b < 1/3 OHContestant = 1; elseif b > 1/3 && b < 2/3 OHContestant = 2; elseif b > 2/3 OHContestant = 3; end %before the host opens a door, is the contestant right? if (doors(OHContestant) == 1) guessRight = guessRight +1; else guessWrong = guessWrong +1; end %the door the car is behind car = find(doors); %omnicient host (OHost) selecting a door with a goat %first 6 cases, the contestant is wrong if OHContestant == 1 && car == 2 OHost = 3; elseif OHContestant == 1 && car == 3 OHost = 2; elseif OHContestant == 2 && car == 1 OHost = 3; elseif OHContestant == 2 && car == 3 OHost = 1; elseif OHContestant == 3 && car == 1 OHost = 2; elseif OHContestant == 3 && car == 2 OHost = 1; %next cases, the contestant is right %now the host has a choice of which goat to reveal %recall, because the contestant guessed correctly, both other doors have %goats, so the host can reveal either one %these if-then statements are nested purely for ease of reading elseif (doors(OHContestant) == 1) if (OHContestant==1) && c < 0.5 OHost = 2; else OHost = 3; end elseif (doors(OHContestant) == 2) if (OHContestant==1) && c < 0.5 OHost = 1; else OHost = 3; end elseif (doors(OHContestant) == 3) if (OHContestant==1) && c < 0.5 OHost = 1; else OHost = 2; end end if (doors(OHContestant) ==0) OHCorrectToSwitch = OHCorrectToSwitch +1; else OHCorrectToStay = OHCorrectToStay +1; end end %These exist for debugging and personal clarity display('Correct guess at first'); guessRight display('Wrong guess at first'); guessWrong display('Should keep the original guess'); OHCorrectToStay/loopLimit display('Should switch guesses'); OHCorrectToSwitch/loopLimit