Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
% Ph = [1/3 1/3 1/3
% 1/3 1/3 1/3
% 1/3 1/3 1/3]
%__________________________________________________________________________
%
% CASE 1A: Host always hides the car behind one particular door.
% Pc = [1 0 0] or [0 1 0] or [0 0 1]
%__________________________________________________________________________
% 1. Pc = [1 0 0], D = 1, H = 3.
% The host always hides the car behind door 1.
% Consequently, a player with an initial door choice of D = 1 cannot win
% by switching doors after the host opens door H = 3 i.e. Psw = 0.
D = 1;
H = 3;
Ph = ones(3)/3;
Pc = [1 0 0];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
% 2. Pc = [1 0 0], D = 1, H = 2.
% The host always hides the car behind door 1.
% Consequently, a player with an initial door choice of D = 1 cannot win
% by switching doors after the host opens door H = 2 i.e. Psw = 0.
D = 1;
H = 2;
Ph = ones(3)/3;
Pc = [1 0 0];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
% 3. Pc = [0 1 0], D = 1, H = 2.
% The host always hides the car behind door 2.
% Consequently, a player with an initial door choice of D = 1 does not
% have the option to switch doors after the host opens door H = 2.
D = 1;
H = 2;
Ph = ones(3)/3;
Pc = [0 1 0];
Pws_correct = NaN;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
% 4. Pc = [0 1 0], D = 1, H = 3.
% The host always hides the car behind door 2.
% Consequently, a player with an initial door choice of D = 1 can only win
% by switching to door 2 after the host opens door H = 3. i.e. Psw = 1.
D = 1;
H = 3;
Ph = ones(3)/3;
Pc = [0 1 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
% 5. Pc = [0 0 1], D = 1, H = 2
% The host always hides the car behind door 3.
% Consequently, a player with an initial door choice of D = 1 does not
% have the option to switch doors after the host opens door H = 2.
D = 1;
H = 2;
Ph = ones(3)/3;
Pc = [0 0 1];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
% 6. Pc = [0 0 1], D = 1, H = 3
% The host always hides the car behind door 3.
% Consequently, a player with an initial door choice of D = 1 does not
% have the option to switch doors after the host opens door H = 3.
D = 1;
H = 3;
Ph = ones(3)/3;
Pc = [0 0 1];
Pws_correct = NaN;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 1B: Host hides the car behind two particular doors with equal probability.
% Pc = [0 0.5 0.5] or [0.5 0.5 0] or [0.5 0 0.5]
%__________________________________________________________________________
% 1. Pc = [0 0.5 0.5], D = 3, H = 1.
% The car is either behind door 2 or 3. If the host opens door H = 1, the
% player's chance of winning by switching from door D = 3 to door 2 is
% equal i.e. Psw = 0.5.
D = 3;
H = 1;
Ph = ones(3)/3;
Pc = [0 0.5 0.5];
Pws_correct = 0.5;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequal(round(Pws,4),Pws_correct))
% 2. Pc = [0 0.5 0.5], D = 3, H = 2.
% The host never hides the car behind door 1. Hence, the player can never
% wi by switching to door 1.
D = 3;
H = 2;
Ph = ones(3)/3;
Pc = [0 0.5 0.5];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequal(round(Pws,4),Pws_correct))
% 3. Pc = [0.5 0.5 0], D = 3, H = 1.
% The host never hides the car behind door 3. Hence, the player can only
% win by switching to door 2.
D = 3;
H = 1;
Ph = ones(3)/3;
Pc = [0.5 0.5 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
% 4. Pc = [0.5 0.5 0], D = 3, H = 2.
% The host never hides the car behind door 3. Hence, the player can only
% win by switching to door 1.
D = 3;
H = 2;
Ph = ones(3)/3;
Pc = [0.5 0.5 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
% 5. Pc = [0.5 0 0.5], D = 3, H = 1.
% The host never hides the car behind door 2. Hence, the player can
% never win by switching to door 2.
D = 3;
H = 1;
Ph = ones(3)/3;
Pc = [0.5 0 0.5];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 1C: Hosts hides the car behind any of the three doors with equal probability.
% Pc = [1/3 1/3 1/3]
%__________________________________________________________________________
% The host does not manipulate the game. Hence, it is a fair game.
D = 1;
H = 3;
Ph = ones(3)/3;
Pc = [1 1 1]/3;
Pws_correct = 0.5;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 1D: Host hides the car with a pre-determined probability.
% Pc = [0.26 0.43 0.31]
%__________________________________________________________________________
D = 1;
H = 3;
Ph = ones(3)/3;
Pc = [0.26 0.43 0.31];
Pws_correct = 0.6232;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 1;
H = 2;
Ph = ones(3)/3;
Pc = [0.26 0.43 0.31];
Pws_correct = 0.5439;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 2;
H = 1;
Ph = ones(3)/3;
Pc = [0.26 0.43 0.31];
Pws_correct = 0.4189;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 2;
H = 3;
Ph = ones(3)/3;
Pc = [0.26 0.43 0.31];
Pws_correct = 0.3768;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = ones(3)/3;
Pc = [0.26 0.43 0.31];
Pws_correct = 0.5811;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = ones(3)/3;
Pc = [0.26 0.43 0.31];
Pws_correct = 0.4561;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
|
2 | Pass |
% Marilyn vos Savant.
% Ph = [ 0 1 0
% 1 0 0
% 0.5 0.5 0]
%__________________________________________________________________________
%
% CASE 2A: Host always hides the car behind one particular door.
% Pc = [1 0 0] or [0 1 0] or [0 0 1]
%__________________________________________________________________________
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [1 0 0];
Pws_correct = NaN;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [1 0 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0 1 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0 1 0];
Pws_correct = NaN;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0 0 1];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0 0 1];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 2B: Host hides the car behind two particular doors with equal
% probability.
% Pc = [0 0.5 0.5] or [0.5 0.5 0] or [0.5 0 0.5]
%__________________________________________________________________________
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.5 0.5 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.5 0.5 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0 0.5 0.5];
Pws_correct = 0.6667;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0 0.5 0.5];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.5 0 0.5];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.5 0 0.5];
Pws_correct = 0.6667;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 2C: Hosts hides the car behind any of the three doors with equal
% probability.
% Pc = [1/3 1/3 1/3]
%__________________________________________________________________________
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [1 1 1]/3;
Pws_correct = 0.6667;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [1 1 1]/3;
Pws_correct = 0.6667;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 2D: Host hides the car with a pre-determined probability.
% Pc = [0.26 0.43 0.31]
%__________________________________________________________________________
D = 1;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.3735;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 2;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.2650;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.7350;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 2;
Ph = [ 0 1 0;
1 0 0;
0.5 0.5 0];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.6265;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
|
3 | Pass |
%__________________________________________________________________________
%
% CASE 3A: Host always hides the car behind one particular door.
% Pc = [1 0 0] or [0 1 0] or [0 0 1]
%__________________________________________________________________________
D = 2;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [1 0 0];
Pws_correct = NaN;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(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];
Pc = [1 0 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 2;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0 1 0];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(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;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 2;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0 0 1];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(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];
Pc = [0 0 1];
Pws_correct = NaN;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 3B: Host hides the car behind two particular doors with equal probability.
% Pc = [0 0.5 0.5] or [0.5 0.5 0] or [0.5 0 0.5]
%__________________________________________________________________________
D = 3;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0 0.5 0.5];
Pws_correct = 0.6136;
Pws = MontyHall3(D,H,Ph,Pc);
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];
Pc = [0 0.5 0.5];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequal(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0.5 0.5 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(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];
Pc = [0.5 0.5 0];
Pws_correct = 1;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0.5 0 0.5];
Pws_correct = 0;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 3C: Hosts hides the car behind any of the three doors with equal
% probability.
% Pc = [1/3 1/3 1/3]
%__________________________________________________________________________
D = 3;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [1 1 1]/3;
Pws_correct = 0.6136;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(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];
Pc = [1 1 1]/3;
Pws_correct = 0.4745;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
%__________________________________________________________________________
%
% CASE 3D: Host hides the car with a pre-determined probability.
% Pc = [0.26 0.43 0.31]
%__________________________________________________________________________
D = 1;
H = 2;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.5690;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 1;
H = 3;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.6274;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 2;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.3123;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(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];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.3726;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
D = 3;
H = 1;
Ph = [0.3333 0.3651 0.3016
0.4646 0.2283 0.3071
0.2926 0.4043 0.3032];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.6877;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(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];
Pc = [0.26 0.43 0.31];
Pws_correct = 0.4310;
Pws = MontyHall3(D,H,Ph,Pc);
assert(isequaln(round(Pws,4),Pws_correct))
|
What is the next step in Conway's Life?
640 Solvers
Create a cell array out of a struct
508 Solvers
199 Solvers
10 Solvers
swap sign sum & multiply castles
30 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!