#Jan. 26, 2015, Math640 (Rutgers University), Class 2 #C2.txt Help:=proc(): print(` MH(), MHs() , BD(k,N) , BDf(k,N) `): print(`SD(p,FP,FN) `): end: #MH(): simulates ONE instance of the Monty Hall game show #where there is a car behind one of the doors (w.l.o.g door #1) #and the two other doors have goats. #implementing the switching stragegy MH:=proc() local door1, UnpickedDoors, MontyDoors,MontyDoor,ND : door1:=rand(1..3)(): print(`You picked door`, door1 ): UnpickedDoors:={1,2,3} minus {door1}: MontyDoors:=UnpickedDoors minus {1}: MontyDoor:=MontyDoors[rand(1..nops(MontyDoors))()]: print(`Monty shows you that door`, MontyDoor, `has a goat `): print(`and he kindly (or "kindly") offers you to switch your`): print(`choice, and you agree`): ND:={1,2,3} minus {door1, MontyDoor}: ND:=ND[1]: print(`You decided to change your guessed door to door`, ND): if ND=1 then print(`Congratulations! You won a Porche! `): else print(`Monty tricked you, have fun with the goat.`): fi: end: #MHs(): simulates ONE instance of the Monty Hall game show #where there is a car behind one of the doors (w.l.o.g #!) #and the two other doors have goats. #implementing the switching stragegy MHs:=proc() local door1, UnpickedDoors, MontyDoors,MontyDoor,ND : door1:=rand(1..3)(): UnpickedDoors:={1,2,3} minus {door1}: MontyDoors:=UnpickedDoors minus {1}: MontyDoor:=MontyDoors[rand(1..nops(MontyDoors))()]: ND:={1,2,3} minus {door1, MontyDoor}: ND:=ND[1]: if ND=1 then true: else false: fi: end: #simulating the birthday problem with k people and #N days (in Planet earth N=365) BD:=proc(k,N) local i: evalb(nops({seq(rand(1..N)(),i=1..k)})=k): end: #Prob. of no-repeated birthdays with k people and N days BDf:=proc(k,N) local i: evalf(mul((1-i/N),i=1..k-1)): end: #SD(p,FP, FN):Stupid Doctors, probability of being #really sick if the doctor said you were sick SD:=proc(p,FP,FN) (p*(1-FN))/(p*(1-FN)+(1-p)*FP): end: