Cody

# Problem 44724. Let's Make A Deal: The Player's Dilemma 2

Solution 1722863

Submitted on 7 Feb 2019 by Alfonso Nieto-Castanon
• Size: 42
• This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
% Ph = [1 0 0 % 0 1 0 % 0 0 1] % In this case, the host does not offer the player the choice of switching % doors. Hence, return Pws = NaN. %__________________________________________________________________________ D = 1; H = 2; Ph = diag([1 1 1]); Pws_correct = NaN; Pws = MontyHall2(D,H,Ph); assert(isequaln(round(Pws,4),Pws_correct)) D = 1; H = 3; Ph = diag([1 1 1]); Pws_correct = NaN; Pws = MontyHall2(D,H,Ph); assert(isequaln(round(Pws,4),Pws_correct)) D = 2; H = 3; Ph = diag([1 1 1]); Pws_correct = NaN; Pws = MontyHall2(D,H,Ph); assert(isequaln(round(Pws,4),Pws_correct))

2   Pass
% Ph = [1/3 1/3 1/3 % 1/3 1/3 1/3 % 1/3 1/3 1/3] % In this case, the game is fair because the host does not make any effort % to open any particular door. Hence, the chance of winning or losing by % switching is equal i.e. Psw = 0.5. %__________________________________________________________________________ D = 1; H = 2; Ph = ones(3)/3; Pws_correct = 0.5; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 1; H = 3; Ph = ones(3)/3; Pws_correct = 0.5; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 2; H = 1; Ph = ones(3)/3; Pws_correct = 0.5; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 2; H = 3; Ph = ones(3)/3; Pws_correct = 0.5; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct))

3   Pass
% the host opens door 3. % Ph = [0 1 0 % 0 0 1 % 0 1 0] %__________________________________________________________________________ D = 1; H = 3; Ph = [0 1 0; 0 0 1; 0 1 0]; Pws_correct = 1; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 1; H = 2; Ph = [0 1 0; 0 0 1; 0 1 0]; Pws_correct = 0.5; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 2; H = 3; Ph = [0 1 0; 0 0 1; 0 1 0]; Pws_correct = 0; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 3; H = 2; Ph = [0 1 0; 0 0 1; 0 1 0]; Pws_correct = 0.5; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct))

4   Pass
% Marilyn vos Savant. %__________________________________________________________________________ D = 3; H = 1; Ph = [ 0 1 0; 1 0 0; 0.5 0.5 0]; Pws_correct = 0.6667; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 3; H = 2; Ph = [ 0 1 0; 1 0 0; 0.5 0.5 0]; Pws_correct = 0.6667; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 2; H = 1; Ph = [ 0 1 0; 1 0 0; 0.5 0.5 0]; Pws_correct = 0.3333; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct))

5   Pass
%__________________________________________________________________________ D = 1; H = 3; Ph = [0.3333 0.3651 0.3016 0.4646 0.2283 0.3071 0.2926 0.4043 0.3032]; Pws_correct = 0.5045; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 2; H = 3; Ph = [0.3333 0.3651 0.3016 0.4646 0.2283 0.3071 0.2926 0.4043 0.3032]; Pws_correct = 0.4955; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 3; H = 2; Ph = [0.3333 0.3651 0.3016 0.4646 0.2283 0.3071 0.2926 0.4043 0.3032]; Pws_correct = 0.4745; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 2; H = 1; Ph = [0.5000 0.1000 0.4000 0.0500 0.5000 0.4500 0.3333 0.0667 0.6000]; Pws_correct = 0.8696; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 2; H = 3; Ph = [0.5000 0.1000 0.4000 0.0500 0.5000 0.4500 0.3333 0.0667 0.6000]; Pws_correct = 0.4706; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct)) D = 3; H = 1; Ph = [0.5000 0.1000 0.4000 0.0500 0.5000 0.4500 0.3333 0.0667 0.6000]; Pws_correct = 0.1304; Pws = MontyHall2(D,H,Ph); assert(isequal(round(Pws,4),Pws_correct))