%% Target
% Robin, Sheriff of Nothingham and King Richard aim and shoot
% at the target. They have a record of hitting the target with
% probabilities 0.8, 0.7, and 0.6 respectivelly.
% They shoot once independently of each other. What is the probability
% that target is hit? Theoretical result is 1-0.2*0.3*0.4 = 1-0.024=0.976

clear all
close all
  disp('Robin, Sheriff of Nothingham and King Richard Target Practice')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  rand('twister',0)
  fs = 15;

N= 10000; %number of shots by the three
hits=[];   %record hits
for i = 1:N
     R = rand < 0.8; %0 if miss/1 if hit
     S = rand < 0.7; %0 if miss/1 if hit
     K = rand < 0.6; %0 if miss/1 if hit
     hit = R+S+K > 0; %target hit 0 no, 1 yes
     hits = [hits hit];  %save result
end
plot( (1:N), cumsum(hits)./(1:N),'k-' )
hold on
plot( (1:N), 0.976.*ones(1,N), 'r:')
hold off
