What Are the Mistakes in This 4-Door Monty Hall Simulation Code in Maple?

  • Context: Maple 
  • Thread starter Thread starter fluffik
  • Start date Start date
  • Tags Tags
    Maple Monty hall
Click For Summary
SUMMARY

The forum discussion focuses on a user's attempt to implement a 4-door Monty Hall simulation in Maple, specifically addressing coding errors in their procedure. Key mistakes identified include the incorrect use of the function 'rendomize()' instead of 'randomize()' and logical flaws in the door selection process. The user seeks guidance on improving their code to accurately simulate the Monty Hall problem, which involves strategic door switching after Monty reveals doors. The discussion emphasizes the importance of correct syntax and logical flow in programming simulations.

PREREQUISITES
  • Familiarity with Maple programming language
  • Understanding of the Monty Hall problem
  • Knowledge of statistical simulations
  • Basic programming concepts such as loops and conditionals
NEXT STEPS
  • Review Maple's documentation on the 'randomize()' function
  • Study the Monty Hall problem and its variations in depth
  • Learn about debugging techniques in Maple
  • Explore statistical analysis methods for simulation results
USEFUL FOR

This discussion is beneficial for Maple programmers, statisticians interested in simulation problems, and educators teaching probability concepts through programming.

fluffik
Messages
2
Reaction score
0
Hi, Iam a new user of Maple and having hard time to figure out what Iam doing wrong.
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 news on Phys.org
Have you tried replacing rendomize() by randomize()?
 
Yes, thank you!
 

Similar threads

  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 212 ·
8
Replies
212
Views
16K
  • · Replies 30 ·
2
Replies
30
Views
4K
  • · Replies 21 ·
Replies
21
Views
16K
Replies
1
Views
2K
  • · Replies 38 ·
2
Replies
38
Views
8K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K