Hi, Iam a new user of Maple and having hard time to figure out what Iam doing wrong.(adsbygoogle = window.adsbygoogle || []).push({});

I need to set up Monty Hall simulation problem with 4 doors. Monty will open door twice and give opportunity to the player to switch the door or not. That's what I came up with. Could anyone point out my mistakes. Thank you

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:

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Monty Hall w/ 4 doors in Maple

Loading...

Similar Threads - Monty Hall doors | Date |
---|---|

I Monty Hall - Multiple solutions via direct calculation? | Mar 8, 2016 |

Not Monty Hall again... | Dec 17, 2015 |

Question on the Logic of the Monty Hall Problem | Apr 11, 2015 |

Modified monty hall problem | Sep 3, 2013 |

Monty Hall Problem - But with 4 doors and two opportunities to switch | Apr 14, 2010 |

**Physics Forums - The Fusion of Science and Community**