Jump to content

Yet Another Monty Hall Simulator


beestinga
 Share

Recommended Posts

Just as the topic says.

You can read about the Monty Hall Problem here:

http://montyhallproblem.com/

I refused to believe it so I wrote a program to simulate and research for myself.

Boy were my cheeks red.

Anyway, here it is, pretty simple and straight forward.

;Monty Hall Simulator
;Not Switching
$wins=0
$losses=0
$runs=0
For $k=1 to 10000
    $winningdoor=random(1,3,1)
    $chosendoor=random(1,3,1)
    $eliminated=random(1,3,1)
    if $eliminated=$winningdoor or $eliminated=$chosendoor Then
        While $eliminated=$winningdoor or $eliminated=$chosendoor
            $eliminated=random(1,3,1)
        WEnd
    EndIf
    If $winningdoor=$chosendoor Then $wins+=1 
    if $winningdoor<>$chosendoor Then $losses+=1
    $runs+=1
Next
MsgBox(0,"All Done!","You won "&$wins&" times and lost "&$losses&" times out of "&$runs&" runs!")

;Now we switch when we get the chance
$wins=0
$losses=0
$runs=0
For $k=1 to 10000
    $winningdoor=random(1,3,1)
    $chosendoor=random(1,3,1)
    $eliminated=random(1,3,1)
    if $eliminated=$winningdoor or $eliminated=$chosendoor Then
        While $eliminated=$winningdoor or $eliminated=$chosendoor
            $eliminated=random(1,3,1)
        WEnd
    EndIf
    $newchosen=random(1,3,1)
    If $newchosen=$eliminated or $newchosen=$chosendoor Then
        While $newchosen=$eliminated or $newchosen=$chosendoor
            $newchosen=random(1,3,1)
        WEnd
    EndIf
    If $winningdoor=$newchosen Then $wins+=1 
    if $winningdoor<>$newchosen Then $losses+=1
    $runs+=1
Next
MsgBox(0,"All Done!","You won "&$wins&" times and lost "&$losses&" times out of "&$runs&" runs!")
Exit
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...