fluff

10 Reputation

One Badge

11 years, 211 days

MaplePrimes Activity


These are replies submitted by fluff

@Carl Love 

Thank you

@Carl Love 

Thank you, I really appreciate your help. 
Hopefully last question, just to clarify. When you ask

MontyHall4(100000);
                             25092
MontyHall4(100000, switch1st);
                             37562
MontyHall4(100000, switch1st, switch2nd);
                             62565
MontyHall4(100000, switch2nd);
                             74751

it represents: (No switches at all)
                  (switch, no switch)
                  (switch, switch)
                   (no switch, switch)

So the conclusion: the best chance the Player has only when he switches the door when only 2 left unopen, right?

If I will try to extend this problem, does it mean, that I sould always stick to my original door till only 2 doors left unopen? 

@Carl Love 

So, if I set the problem as you told me: MontyHall:= proc(N::posint, {switches::identical(0,1,2):= 0})

 how do I define switches in the middle of the problem?

There is my solution, where Am I making mistake? Thanks

restart;
with(Statistics):
rendomize():
MontyHall:=proc(N::posint,{switches::identical(0,1,2):=0})

# Simulations for the 4-door Monty Hall problem.

N is the # of trials. Returns the number of trials the player wins.
local
wins:=0,
Car,# the door with the Car behind it(1..4).
Montys1stDoor, # The door that Monty reveals first(1..4).
Montys2ndDoor, # The door that Monty reveals second(1..3).
Players1stDoor, # The door the player picks first.
Players2ndDoor, # The door the player picks second.
Players3rdDoor, # The door the player picks third.
Doors:={1,2,3,4},

rand4:=rand(1..4),rand3:=rand(1..3),rand2:=rand(1..2);
to N do Car:=rand4();
Players1stDoor:=rand4();
if Players1stDoor=Car then
Montys1stDoor:=(Doors minus{Car})[rand3()]
else
Montys1stDoor:=(Doors minus{Car,Players1stDoor})[]
end if;

if switches then

Players2ndDoor:=(Doors minus{Montys1stDoor,Players1stDoor})[rand2()]

else

Players2ndDoor:=Players1stDoor end if;

if Players2ndDoor=Car then
Montys2ndDoor:=(Doors minus{Car,Montys1stDoor})[rand2()]
else
Montys2ndDoor:=(Doors minus{Car,Montys1stDoor,Players2ndDoor})[]
end if;

if switches then

Players3rdDoor:=(Doors-{Montys1stDoor,Montys2ndDoor,Players2ndDoor})[]

else

Players3rdDoor:=Players2ndDoor end if; if Players3rdDoor=Car then
wins:=wins+1;
end if
end do;
wins
end proc:

There is my final "draft" but I know I have mistakes there, could anybody check it and pointed out what I did wrong, I would realy appreciated. Iam still confused how to set a probel correctly, when Iam saying MontyHall:=proc

 Thanks

restart;
with(Statistics):
rendomize():
MontyHall:=proc(N::posint,{switch::truefalse:=false})

# Simulations for the 4-door Monty Hall problem. N is the # of trials. Returns the number of trials the player wins.
local
wins:=0,
Car,# the door with the Car behind it(1..4).
Montys1stDoor, # The door that Monty reveals first(1..4).
Montys2ndDoor, # The door that Monty reveals second(1..3).
Players1stDoor, # The door the player picks first.
Players2ndDoor, # The door the player picks second.
Players3rdDoor, # The door the player picks third.
Doors:={1,2,3,4},

switch:=switch1,switch2;

rand4:=rand(1..4),rand3:=rand(1..3),rand2:=rand(1..2);
to N do
Car:=rand4();
Players1stDoor:=rand4();
if Players1stDoor=Car then
Montys1stDoor:=(Doors minus{Car})[rand3()]
else
Montys1stDoor:=(Doors minus{Car,Players1stDoor})[]
end if;

if switch1 then

Players2ndDoor:=(Doors minus{Montys1stDoor,Players1stDoor})[rand2()]

else

Players2ndDoor:=Players1stDoor end if;

if Players2ndDoor=Car then
Montys2ndDoor:=(Doors minus{Car,Montys1stDoor})[rand2()]
else
Montys2ndDoor:=(Doors minus{Car,Montys1stDoor,Players2ndDoor})[]
end if;

if switch2 then

Players3rdDoor:=(Doors-{Montys1stDoor,Montys2ndDoor,Players2ndDoor})[]

else

Players3rdDoor:=Players2ndDoor end if;

if Players3rdDoor=Car then
wins:=wins+1;
end if
end do;
wins
end proc:

@Carl Love 

I need to consider 4 options:

No switch, No switch: Players1Door=Players2Door=Players3Door

No switch, Switch: Players1Door=Players2Door

                        Players3Door=(Doors minus{MontyDoor1,MontyDoor2,Players2Door})[]

Switch, No switch: Players2Door:=(Doors minus{Players1Door,MontyDoor1})[rand2()]

                        Players3Door:=Players2Door

Switch, Switch: Players2Door:=(Doors minus{MontyDoor1,Players1Door})[rand2()]

                    Players3Door:=(Doors minus{MontyDoor1,Players1Door,MontyDoor2})[];

Iam not sure how I can declare that...

Can I do them all at once or maybe I can ran 4 different programs? Whats easier?

 

@acer 

Yep, I figured out. I also typed ens instead of end... Thanks 

I did the 4 door and not sure if I did switches correctly. Could you take a look?

if switch then
Players2ndDoor:=(Doors minus{Montys1stDoor,Players1stDoor})[]
else
Players2ndDoor:=Players1stDoor
end if;
if switch then
Players3rdDoor:=(Doors minus{Montys1stDoor,Montys2ndDoor,Players1stDoor})[]
else
Players3rdDoor:=Players1stDoor
end if;
if Players3rdDoor=Car then
wins:=wins+1;
end if
end do;
wins
end proc:
MontyHall(10000);
2422
MontyHall(10000,switch);
7448
MontyHall(10000,switch,switch);
7526

@Carl Love 

Thanks, I think Iam able to understand now and see how you can set up a problem like that. The only one thing, that Iam still confused with some operators and keep getting a msg error. Can you see what Iam doing wrong? When I press Enter after last line (end proc:) I have an error msg and its shows at the 5th line from the bottom (  wins:=wins+1;) Can you tell me what operator am I missing? Thanks

>restart;
>with(Statistics):
>rendomize():
>MontyHall:=proc(N::posint,{switch::truefalse:=false})
># Simulations for the 3-door Monty Hall problem. N is the

   # of trials. Returns the number of trials the player wins.
local

wins:=0,
Car,# the door with the Car behind it(1..3).
MontysDoor,# The door that Monty reveals(1..3).
Player1stDoor, # The door the player picks first.
Player2ndDoor, # The door the player picks second.
Doors:={1,2,3},
rand3:=rand(1..3),rand2:=rand(1..2);
to N do
Car:=rand3();
Players1stDoor:=rand3();
if Players1stDoor=Car then
MontysDoor:=(Doors minus{Car})[rand2()]
else
MontysDoor:=(Doors minus{Car,Players1stDoor})[]
end if;

if switches then

Players2ndDoor:=(Doors minus{MontysDoor,Players1stDoor})[]

else

Players2ndDoor:=Players1stDoor

end if;

if Players2ndDoor=Car then

wins:=wins+1;

end if

end do;

wins

ens proc:

Error, missing operator or `;`

@Carl Love Yes, I need to use random number simulations. And I also asked to show what happens when you switch the door and what happens whem you don't switch the door.

Page 1 of 1