Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Monty-Hall-problem/FreeBASIC/monty-hall-problem.basic
Normal file
35
Task/Monty-Hall-problem/FreeBASIC/monty-hall-problem.basic
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
' 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue