Monty Hall problem: Difference between revisions

m
one variable eliminated
m (one variable eliminated)
Line 1,701:
 
<lang Mathematica> montyHall[nGames_] :=
Module[{r, winningDoors, firstChoices, nStayWins, stayWinPercent, nSwitchWins},
r := RandomInteger[{1, 3}, nGames];
winningDoors = r;
firstChoices = r;
nStayWins = Count[Transpose[{winningDoors, firstChoices}], {d_, d_}];
stayWinPercent = N[100 nStayWins/nGames];
nSwitchWins = nGames - nStayWins;
Grid[{{"Strategy", "Wins", "Win %"}, {"Stay", Row[{nStayWins, "/", nGames}], stayWinPercentN[100 nStayWins/nGames]},
{"Switch", Row[{nSwitchWins, "/", nGames}], 100 - stayWinPercent}}, Frame -> All]]</lang>