Monty Hall problem: Difference between revisions
Content added Content deleted
(Add Swift) |
No edit summary |
||
Line 2,255: | Line 2,255: | ||
win 33.3008% 66.6487% |
win 33.3008% 66.6487% |
||
win not 66.6992% 33.3513%</pre> |
win not 66.6992% 33.3513%</pre> |
||
=={{header|M2000 Interpreter}}== |
|||
<lang M2000 Interpreter> |
|||
Module CheckIt { |
|||
Enum Strat {Stay, Random, Switch} |
|||
total=10000 |
|||
Print $("0.00") |
|||
player_win_stay=0 |
|||
player_win_switch=0 |
|||
player_win_random=0 |
|||
For i=1 to total { |
|||
Dim doors(1 to 3)=False |
|||
doors(Random(1,3))=True |
|||
guess=Random(1,3) |
|||
Inventory other |
|||
for k=1 to 3 { |
|||
If k <> guess Then Append other, k |
|||
} |
|||
If doors(guess) Then { |
|||
Mont_Hall_show=other(Random(0,1)!) |
|||
} Else { |
|||
If doors(other(0!)) Then { |
|||
Mont_Hall_show=other(1!) |
|||
} Else Mont_Hall_show=other(0!) |
|||
Delete Other, Mont_Hall_show |
|||
} |
|||
Strategy=Each(Strat) |
|||
While Strategy { |
|||
Select Case Eval(strategy) |
|||
Case Randomedit |
|||
{ |
|||
If Random(1,2)=1 Then { |
|||
If doors(guess) Then player_win_Random++ |
|||
} else If doors(other(0!)) Then player_win_Random++ |
|||
} |
|||
Case Switch |
|||
If doors(other(0!)) Then player_win_switch++ |
|||
Else |
|||
If doors(guess) Then player_win_stay++ |
|||
End Select |
|||
} |
|||
} |
|||
Print "Stay: ";player_win_stay/total*100;"%" |
|||
Print "Random: ";player_win_Random/total*100;"%" |
|||
Print "Switch: ";player_win_switch/total*100;"%" |
|||
} |
|||
CheckIt |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Stay: 33.39% |
|||
Random: 51.00% |
|||
Switch: 66.61% |
|||
</pre> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |