Jump to content
Sign in to follow this  
beestinga

Yet Another Monty Hall Simulator

Recommended Posts

beestinga

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

Share this post


Link to post
Share on other sites
enaiman

Simple script and effective ;)

I like it; especially the way you dealt with the while loops.

~ Thumbs up ~


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
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
Sign in to follow this  

×