Monty Hall problem: Difference between revisions

Line 941:
Output:
<pre>Iterations: 10000 - Stayed wins: 3331 (33.31%) - Switched wins: 6669 (66.69%)</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>Procedure MontyHall(Redecide)
Static Dim Doors(2)
Doors(0) = 0
Doors(1) = 0
Doors(2) = 0
Doors(Random(2)) = 1
Pick = 2
Open = 0
If Doors(0)
Open = 1
EndIf
If Redecide
Pick = 1-Open
EndIf
Debug pick
ProcedureReturn Doors(Pick)
EndProcedure
 
OpenConsole()
#Tries = 10000000
For I = 0 To #Tries
Win1 + MontyHall(1)
Debug "--"
Next
 
For I = 0 To #Tries
Win2 + MontyHall(0)
Next
 
PrintN("Trial runs for each option: " + Str(#Tries))
PrintN("Wins when redeciding: " + Str(Win1) + " (" + StrD(Win1/#Tries*100, 2) + "% chance)")
PrintN("Wins when sticking: " + Str(Win2) + " (" + StrD(Win2/#Tries*100, 2) + "% chance)")
Input()</lang>
 
Output:
Trial runs for each option: 10000000
Wins when redeciding: 6663398 (66.63% chance)
Wins when sticking: 3332060 (33.32% chance)
 
=={{header|Python}}==
Anonymous user