Jump to content
Macro Express Forums

The "Monty Hall" problem. I had to prove it to myself.


marshach

Recommended Posts

I recently learned about the so-called "Monty Hall" problem. Like many people, I found it hard to believe that you have a better chance of winning if you switch doors. So, it occured to me that I could "prove" it to myself by writing a macro. Here it is, and it works! (Woo hoo!) (I'm not a professional macro writer. There might be a more efficient way to write a macro to demonstrate the problem.) (Direct edit text attached)

 

// N1 is your decision to keep your original door or switch doors
// N2 is the winning door
// N3 is your original door choice

// N4 is the number of times you win
// N5 is the number of times you lose

// T1 is your decision to keep your original door or switch doors
// T2 is the winning door
// T3 is your original door choice

// A=Keep, B=Switch
Multiple Choice Menu: Keep or Switch?
If Variable %T1% = "A"
Variable Set Integer %N1% to 0
Else
Variable Set Integer %N1% to 1
End If

Repeat Start (Repeat 1000 times)

// N2 (also T2) is the *winning* door (set randomly)

// Maxium Random Value set to 2. (0=door A, 1=door B, 2=door C)
Variable Set Integer %N2% with a Random Number
If Variable %N2% = 0
Variable Set String %T2% "Door A"
End If
If Variable %N2% = 1
Variable Set String %T2% "Door B"
End If
If Variable %N2% = 2
Variable Set String %T2% "Door C"
End If

// N3 (also T3) is your original door choice (set randomly).

// Maxium Random Value set to 2. (0=door A, 1=door B, 2=door C)
Variable Set Integer %N3% with a Random Number
If Variable %N3% = 0
Variable Set String %T3% "Door A"
End If
If Variable %N3% = 1
Variable Set String %T3% "Door B"
End If
If Variable %N3% = 2
Variable Set String %T3% "Door C"
End If

// N1 is your decision (0 = Keep the original door), (1 = Switch doors)
// If you keep the original door

If Variable %N1% = 0
// ...and you had originally picked the winning door
If Variable %T2% = variable %T3%
// You win :-)
Variable Modify Integer: %N4% = %N4% + 1
Else
// ...and you had originally picked a losing door
// You lose :-(

Variable Modify Integer: %N5% = %N5% + 1
End If
Else
// If you switch doors

// ...and you had originally picked the winning door
If Variable %T2% = variable %T3%
// You lose :-(
Variable Modify Integer: %N5% = %N5% + 1
Else
// ...and you had originally picked a losing door
// You win :-)

Variable Modify Integer: %N4% = %N4% + 1
End If
End If

Repeat End

 

// Wins = %N4%, Losses = %N5%
Text Box Display: Wins and losses

Edited by marshach
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...