Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Monty Hall Simulation
#5
Here's my sim:

Code: (Select All)
Dim door(1 To 3)
Const Limit = 1000 'number of games to play without switching, and then repeat that number and switch
Randomize Timer


For i = 1 To Limit
    Print "Game #"; i
    prize = Int(Rnd * 3) + 1 'which door is the prize behind?
    Print "Is it behind Door #1, #2, or #3?"
    guess = Int(Rnd * 3) + 1 'where is our initial guess
    Print "I guess door #"; guess
    'here we can waste some time not swapping
    If guess = prize Then eliminate = guess + 1: If eliminate > 3 Then eliminate = 1

    Print "It's not behind door #"; eliminate; "!  Will you swap?"
    Print "Nope!  I want to keep my choice."
    Print "Since you're keeping it, let's see what happens!"
    If guess = prize Then
        win = win + 1
        Print "You win the car!"
    Else
        lose = lose + 1
        Print "Sorry!  It was behind door #"; prize
    End If
Next

Print "Of "; Limit; "games, you won "; win; "times and lost "; lose; "times by not swapping!"
Sleep


For i = 1 To Limit
    Print "Game #"; i
    prize = Int(Rnd * 3) + 1 'which door is the prize behind?
    Print "Is it behind Door #1, #2, or #3?"
    guess = Int(Rnd * 3) + 1 'where is our initial guess
    Print "I guess door #"; guess
    'here we can waste some time not swapping
    If guess = prize Then eliminate = guess + 1: If eliminate > 3 Then eliminate = 1

    Print "It's not behind door #"; eliminate; "!  Will you swap?"
    Print "Nope!  I want to keep my choice."
    Print "Since you're keeping it, let's see what happens!"
    If guess = prize Then
        lose2 = lose2 + 1
        Print "Sorry!  It was behind door #"; eliminate
    Else
        win2 = win2 + 1
        Print "You win the car!"

    End If
Next

Print "Of "; Limit; "games, you won "; win2; "times and lost "; lose2; "times by swapping!"
Print
Print "To compare:"
Print "Of "; Limit; "games, you won "; win; "times and lost "; lose; "times by not swapping!"
Reply


Messages In This Thread
Monty Hall Simulation - by dcromley - 08-16-2022, 03:51 PM
RE: Monty Hall Simulation - by bplus - 08-16-2022, 04:23 PM
RE: Monty Hall Simulation - by SMcNeill - 08-16-2022, 04:46 PM
RE: Monty Hall Simulation - by bplus - 08-16-2022, 05:00 PM
RE: Monty Hall Simulation - by SMcNeill - 08-16-2022, 05:01 PM
RE: Monty Hall Simulation - by bplus - 08-16-2022, 05:09 PM
RE: Monty Hall Simulation - by SMcNeill - 08-16-2022, 05:11 PM
RE: Monty Hall Simulation - by bplus - 08-16-2022, 05:27 PM
RE: Monty Hall Simulation - by SMcNeill - 08-16-2022, 05:42 PM
RE: Monty Hall Simulation - by Jack - 08-16-2022, 05:45 PM
RE: Monty Hall Simulation - by SMcNeill - 08-16-2022, 06:02 PM
RE: Monty Hall Simulation - by Kernelpanic - 08-16-2022, 07:40 PM
RE: Monty Hall Simulation - by Pete - 08-17-2022, 01:56 AM



Users browsing this thread: 2 Guest(s)