淘客熙熙

主题:【文摘】一道有趣的概率题 -- 天下第一银杏树

共:💬28 🌺15 新:
全看分页树展 · 主题 跟帖
家园 my annotated MATLAB code. How about ur manual list?

N = 1e3; % total # of runs

% behind door # 1 is the car. This configuration is fixed, while your draws are random.

Upick = ceil(3*rand(N,1)); % the door you picked in each of N runs.

P_no_swtch = length(find(Upick==1))/N; % probability of getting the car if you don't switch

SWTCH = [0, 3, 2;

3, 0, 1;

2, 1, 0]; % SWTCH(a,b) denotes the target door as you switch, when you have

% picked door #a, and the host has showed door #b.

P_swtch = 0; % Initialize: probability of getting the car if you do switch

for k = 1:N

host = ceil(3*rand(1)); % the host randomly picks a door, #1->#3

while host == Upick(k) || host ==1 % this door has to be different

host = ceil(3*rand(1)); % from your door, and it has to reveal a goat.

end

NewChoice= SWTCH(Upick(k), host);

if NewChoice == 1 % is a car

P_swtch = P_swtch + 1; % accumulate the hits

end

end

P_swtch = P_swtch/N;

%% Conclusion:

[P_no_swtch, P_swtch]

% == [0.3320, 0.6680], i.e., [1/3, 2/3]. Therefore switching is preferable.


本帖一共被 1 帖 引用 (帖内工具实现)
全看分页树展 · 主题 跟帖


有趣有益,互惠互利;开阔视野,博采众长。
虚拟的网络,真实的人。天南地北客,相逢皆朋友

Copyright © cchere 西西河