Bob participates in a shooting contest. The contest contains 5 rounds, each allowing 2 shots at a specific target, up to 2 shots if needed. Bob hitting probability is 80% .
Evaluate his p(4)/p(3) ratio if
a. p(i) is defined as hitting the target i times out of 5.
OR
b. Hitting the target i consecutive rounds out of 5.
clearvars,clc
global set series hiconsec consecval
set={}; consecval=[];
series=[];
build();
tot=0;
ptot=sym(zeros(1,5)); ptot0=sym(0);
ptotc=sym(zeros(1,5)); ptotc0=sym(0);
for i=1:length(set)
series=set{i};
p=sym(1);
for j=1:length(series)
if series(j)=='h'
p=p*.8;
else
p=p*.2;
end
end
fprintf('%-12s %8.6f %5d\n',series,p,consecval(i))
tot=tot+p;
hct=length(find(series=='h'));
if hct==0
ptot0=ptot0+p;
else
ptot(hct)=ptot(hct)+p;
end
if hct==0
ptotc0=ptotc0+p;
else
ptotc(consecval(i))=ptotc(consecval(i))+p;
end
end
tot
fprintf('%2d %12.9f %-30s %12.9f\n',0,ptot0,ptot0,ptotc0)
cu=ptot0;
for hct=1:5
fprintf('%2d %12.9f %-17s %12.9f %12.9f %-17s\n',hct,ptot(hct),ptot(hct),1-cu,ptotc(hct),ptotc(hct))
cu=cu+ptot(hct);
end
function build()
global set series hiconsec consecval
for result=['h' 'm']
series=[series result];
% Now evaluate if Bob's turn is over
pos=0; over=true;
if isequal(series,'hhhhmmmh')
aa=99;
end
consec=0; hiconsec=0;
for round=1:5
attempt=1;
pos=pos+1;
if pos>length(series)
over=false;
break
end
if series(pos)=='h'
consec=consec+1;
if consec>hiconsec
hiconsec=consec;
end
continue
end
attempt=attempt+1;
if attempt>2
consec=0;
continue
end
pos=pos+1;
if pos>length(series)
over=false;
break
elseif series(pos)=='h'
consec=consec+1;
if consec>hiconsec
hiconsec=consec;
end
elseif attempt==2
consec=0;
end
end
if over
set{end+1}=series;
consecval(end+1)=hiconsec;
consec=0;
else
build;
end
series(end)=[];
end
end
finds the 243 possible sequences of hits and misses during the 5 frounds, and shows the probability of each taking place. For sanity checks, each row shows the number of consicutive rounds in which there was a hit, and at the bottom shows the total of the found probabilities as being 1.
hhhhh 0.327680 5
hhhhmh 0.065536 5
hhhhmm 0.016384 4
hhhmhh 0.065536 5
hhhmhmh 0.013107 5
hhhmhmm 0.003277 4
hhhmmh 0.016384 3
hhhmmmh 0.003277 3
hhhmmmm 0.000819 3
hhmhhh 0.065536 5
hhmhhmh 0.013107 5
hhmhhmm 0.003277 4
hhmhmhh 0.013107 5
hhmhmhmh 0.002621 5
hhmhmhmm 0.000655 4
hhmhmmh 0.003277 3
hhmhmmmh 0.000655 3
hhmhmmmm 0.000164 3
hhmmhh 0.016384 2
hhmmhmh 0.003277 2
hhmmhmm 0.000819 2
hhmmmhh 0.003277 2
hhmmmhmh 0.000655 2
hhmmmhmm 0.000164 2
hhmmmmh 0.000819 2
hhmmmmmh 0.000164 2
hhmmmmmm 0.000041 2
hmhhhh 0.065536 5
hmhhhmh 0.013107 5
hmhhhmm 0.003277 4
hmhhmhh 0.013107 5
hmhhmhmh 0.002621 5
hmhhmhmm 0.000655 4
hmhhmmh 0.003277 3
hmhhmmmh 0.000655 3
hmhhmmmm 0.000164 3
hmhmhhh 0.013107 5
hmhmhhmh 0.002621 5
hmhmhhmm 0.000655 4
hmhmhmhh 0.002621 5
hmhmhmhmh 0.000524 5
hmhmhmhmm 0.000131 4
hmhmhmmh 0.000655 3
hmhmhmmmh 0.000131 3
hmhmhmmmm 0.000033 3
hmhmmhh 0.003277 2
hmhmmhmh 0.000655 2
hmhmmhmm 0.000164 2
hmhmmmhh 0.000655 2
hmhmmmhmh 0.000131 2
hmhmmmhmm 0.000033 2
hmhmmmmh 0.000164 2
hmhmmmmmh 0.000033 2
hmhmmmmmm 0.000008 2
hmmhhh 0.016384 3
hmmhhmh 0.003277 3
hmmhhmm 0.000819 2
hmmhmhh 0.003277 3
hmmhmhmh 0.000655 3
hmmhmhmm 0.000164 2
hmmhmmh 0.000819 1
hmmhmmmh 0.000164 1
hmmhmmmm 0.000041 1
hmmmhhh 0.003277 3
hmmmhhmh 0.000655 3
hmmmhhmm 0.000164 2
hmmmhmhh 0.000655 3
hmmmhmhmh 0.000131 3
hmmmhmhmm 0.000033 2
hmmmhmmh 0.000164 1
hmmmhmmmh 0.000033 1
hmmmhmmmm 0.000008 1
hmmmmhh 0.000819 2
hmmmmhmh 0.000164 2
hmmmmhmm 0.000041 1
hmmmmmhh 0.000164 2
hmmmmmhmh 0.000033 2
hmmmmmhmm 0.000008 1
hmmmmmmh 0.000041 1
hmmmmmmmh 0.000008 1
hmmmmmmmm 0.000002 1
mhhhhh 0.065536 5
mhhhhmh 0.013107 5
mhhhhmm 0.003277 4
mhhhmhh 0.013107 5
mhhhmhmh 0.002621 5
mhhhmhmm 0.000655 4
mhhhmmh 0.003277 3
mhhhmmmh 0.000655 3
mhhhmmmm 0.000164 3
mhhmhhh 0.013107 5
mhhmhhmh 0.002621 5
mhhmhhmm 0.000655 4
mhhmhmhh 0.002621 5
mhhmhmhmh 0.000524 5
mhhmhmhmm 0.000131 4
mhhmhmmh 0.000655 3
mhhmhmmmh 0.000131 3
mhhmhmmmm 0.000033 3
mhhmmhh 0.003277 2
mhhmmhmh 0.000655 2
mhhmmhmm 0.000164 2
mhhmmmhh 0.000655 2
mhhmmmhmh 0.000131 2
mhhmmmhmm 0.000033 2
mhhmmmmh 0.000164 2
mhhmmmmmh 0.000033 2
mhhmmmmmm 0.000008 2
mhmhhhh 0.013107 5
mhmhhhmh 0.002621 5
mhmhhhmm 0.000655 4
mhmhhmhh 0.002621 5
mhmhhmhmh 0.000524 5
mhmhhmhmm 0.000131 4
mhmhhmmh 0.000655 3
mhmhhmmmh 0.000131 3
mhmhhmmmm 0.000033 3
mhmhmhhh 0.002621 5
mhmhmhhmh 0.000524 5
mhmhmhhmm 0.000131 4
mhmhmhmhh 0.000524 5
mhmhmhmhmh 0.000105 5
mhmhmhmhmm 0.000026 4
mhmhmhmmh 0.000131 3
mhmhmhmmmh 0.000026 3
mhmhmhmmmm 0.000007 3
mhmhmmhh 0.000655 2
mhmhmmhmh 0.000131 2
mhmhmmhmm 0.000033 2
mhmhmmmhh 0.000131 2
mhmhmmmhmh 0.000026 2
mhmhmmmhmm 0.000007 2
mhmhmmmmh 0.000033 2
mhmhmmmmmh 0.000007 2
mhmhmmmmmm 0.000002 2
mhmmhhh 0.003277 3
mhmmhhmh 0.000655 3
mhmmhhmm 0.000164 2
mhmmhmhh 0.000655 3
mhmmhmhmh 0.000131 3
mhmmhmhmm 0.000033 2
mhmmhmmh 0.000164 1
mhmmhmmmh 0.000033 1
mhmmhmmmm 0.000008 1
mhmmmhhh 0.000655 3
mhmmmhhmh 0.000131 3
mhmmmhhmm 0.000033 2
mhmmmhmhh 0.000131 3
mhmmmhmhmh 0.000026 3
mhmmmhmhmm 0.000007 2
mhmmmhmmh 0.000033 1
mhmmmhmmmh 0.000007 1
mhmmmhmmmm 0.000002 1
mhmmmmhh 0.000164 2
mhmmmmhmh 0.000033 2
mhmmmmhmm 0.000008 1
mhmmmmmhh 0.000033 2
mhmmmmmhmh 0.000007 2
mhmmmmmhmm 0.000002 1
mhmmmmmmh 0.000008 1
mhmmmmmmmh 0.000002 1
mhmmmmmmmm 0.000000 1
mmhhhh 0.016384 4
mmhhhmh 0.003277 4
mmhhhmm 0.000819 3
mmhhmhh 0.003277 4
mmhhmhmh 0.000655 4
mmhhmhmm 0.000164 3
mmhhmmh 0.000819 2
mmhhmmmh 0.000164 2
mmhhmmmm 0.000041 2
mmhmhhh 0.003277 4
mmhmhhmh 0.000655 4
mmhmhhmm 0.000164 3
mmhmhmhh 0.000655 4
mmhmhmhmh 0.000131 4
mmhmhmhmm 0.000033 3
mmhmhmmh 0.000164 2
mmhmhmmmh 0.000033 2
mmhmhmmmm 0.000008 2
mmhmmhh 0.000819 2
mmhmmhmh 0.000164 2
mmhmmhmm 0.000041 1
mmhmmmhh 0.000164 2
mmhmmmhmh 0.000033 2
mmhmmmhmm 0.000008 1
mmhmmmmh 0.000041 1
mmhmmmmmh 0.000008 1
mmhmmmmmm 0.000002 1
mmmhhhh 0.003277 4
mmmhhhmh 0.000655 4
mmmhhhmm 0.000164 3
mmmhhmhh 0.000655 4
mmmhhmhmh 0.000131 4
mmmhhmhmm 0.000033 3
mmmhhmmh 0.000164 2
mmmhhmmmh 0.000033 2
mmmhhmmmm 0.000008 2
mmmhmhhh 0.000655 4
mmmhmhhmh 0.000131 4
mmmhmhhmm 0.000033 3
mmmhmhmhh 0.000131 4
mmmhmhmhmh 0.000026 4
mmmhmhmhmm 0.000007 3
mmmhmhmmh 0.000033 2
mmmhmhmmmh 0.000007 2
mmmhmhmmmm 0.000002 2
mmmhmmhh 0.000164 2
mmmhmmhmh 0.000033 2
mmmhmmhmm 0.000008 1
mmmhmmmhh 0.000033 2
mmmhmmmhmh 0.000007 2
mmmhmmmhmm 0.000002 1
mmmhmmmmh 0.000008 1
mmmhmmmmmh 0.000002 1
mmmhmmmmmm 0.000000 1
mmmmhhh 0.000819 3
mmmmhhmh 0.000164 3
mmmmhhmm 0.000041 2
mmmmhmhh 0.000164 3
mmmmhmhmh 0.000033 3
mmmmhmhmm 0.000008 2
mmmmhmmh 0.000041 1
mmmmhmmmh 0.000008 1
mmmmhmmmm 0.000002 1
mmmmmhhh 0.000164 3
mmmmmhhmh 0.000033 3
mmmmmhhmm 0.000008 2
mmmmmhmhh 0.000033 3
mmmmmhmhmh 0.000007 3
mmmmmhmhmm 0.000002 2
mmmmmhmmh 0.000008 1
mmmmmhmmmh 0.000002 1
mmmmmhmmmm 0.000000 1
mmmmmmhh 0.000041 2
mmmmmmhmh 0.000008 2
mmmmmmhmm 0.000002 1
mmmmmmmhh 0.000008 2
mmmmmmmhmh 0.000002 2
mmmmmmmhmm 0.000000 1
mmmmmmmmh 0.000002 1
mmmmmmmmmh 0.000000 1
mmmmmmmmmm 0.000000 0
tot =
1
The rest of the program, for each of the five possible hit counts, gives:
the probability of that many hits (decimal and fractional form),
the probability of at least that many (decimal only)
the probability of that many consecutive rounds with a hit (decimal and fractional)
hits all at least consecutive
decimal rational decimal rational
0 0.000000102 1/9765625 0.000000102
1 0.000012288 24/1953125 0.999999898 0.001781760 696/390625
2 0.000589824 1152/1953125 0.999987610 0.042703258 417024/9765625
3 0.014155776 27648/1953125 0.999397786 0.072194458 705024/9765625
4 0.169869312 331776/1953125 0.985242010 0.067947725 663552/9765625
5 0.815372698 7962624/9765625 0.815372698 0.815372698 7962624/9765625
So, to answer the questions:
p(4)/p(3)
a. 331776/27648 = 12
b. 663552/705024 = 16/17
|
Posted by Charlie
on 2023-03-15 10:06:15 |