# Yet Another Monty Hall Simulator

## Recommended Posts

Just as the topic says.

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 on other sites

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 :)

## Create an account

Register a new account