# PROBLEM DESCRIPTION # # Prisoner 1 asks the guard for additional information # # If Prisoner 2 is pardoned, guard names Prisoner 3 # # If Prisoner 3 is pardoned, guard names Prisoner 2 # # If Prisoner 1 is pardoned, guard names Prisoner 2 # with prob 1/2 and 3 with prob 1/2 # Given that the guard named Prisoner 2, the prob of # being pardoned becomes 1/3 for Prisoner 1 and 2/3 # for Prisoner 3. ########################################################### N = 10000 # number of simulations x = 1:N # pardoned prisoner y = 1:N # guard disclosure of non-pardoned prisoner for (i in 1:N) { s = sample(1:3); x[i] = s[1]; if(x[i] == 1){y[i] = sample(2:3)[1]}; if(x[i] == 2){y[i] = 3}; if(x[i] == 3){y[i] = 2}; } sum(x==1 & y==2)/sum(y==2) # P( 1 | guard names 2 ) sum(x==3 & y==2)/sum(y==2) # P( 3 | guard names 2 ) sum(x==1 & y==3)/sum(y==3) # P( 1 | guard names 3 ) sum(x==2 & y==3)/sum(y==3) # P( 2 | guard names 3 )