Monty Hall problem: Difference between revisions
Content added Content deleted
(→{{header|BASIC}}: Added Minimal BASIC.) |
(→{{header|BASIC}}: FreeBASIC restored (previously removed by mistake).) |
||
Line 651: | Line 651: | ||
Switching wins 6697 times. |
Switching wins 6697 times. |
||
Staying wins 3303 times. |
Staying wins 3303 times. |
||
</pre> |
|||
==={{header|FreeBASIC}}=== |
|||
<syntaxhighlight lang="freebasic"> |
|||
' version 19-01-2019 |
|||
' compile with: fbc -s console |
|||
Const As Integer max = 1000000 |
|||
Randomize Timer |
|||
Dim As UInteger i, car_door, chosen_door, montys_door, stay, switch |
|||
For i = 1 To max |
|||
car_door = Fix(Rnd * 3) + 1 |
|||
chosen_door = Fix(Rnd * 3) + 1 |
|||
If car_door <> chosen_door Then |
|||
montys_door = 6 - car_door - chosen_door |
|||
Else |
|||
Do |
|||
montys_door = Fix(Rnd * 3) + 1 |
|||
Loop Until montys_door <> car_door |
|||
End If |
|||
'Print car_door,chosen_door,montys_door |
|||
' stay |
|||
If car_door = chosen_door Then stay += 1 |
|||
' switch |
|||
If car_door = 6 - montys_door - chosen_door Then switch +=1 |
|||
Next |
|||
Print Using "If you stick to your choice, you have a ##.## percent" _ |
|||
+ " chance to win"; stay / max * 100 |
|||
Print Using "If you switched, you have a ##.## percent chance to win"; _ |
|||
switch / max * 100 |
|||
' empty keyboard buffer |
|||
While InKey <> "" : Wend |
|||
Print : Print "hit any key to end program" |
|||
Sleep |
|||
End |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
If you stick to your choice, you have a 33.32 percent chance to win |
|||
If you switched, you have a 66.68 percent chance to win |
|||
</pre> |
</pre> |
||