# Sheldon Ross 10: Exercise 3.29  Question: Two players take turns shooting at a target, with each shot by player i hitting the with probability pi , i = 1, 2. Shooting ends when two consecutive shots hit target. Let μi denote the mean number of shots taken when player i shoots first, = 1, 2.

• Find μ1 and μ2
• Let hi denote the mean number of times that the target is hit when player i shoots first, i = 1, 2. Find h1 and h2

Analytical Solution

This problem is also an extension of the Exercise 3.26 and the solution can be obtained by tweaking the result from that problem. The simulation and the code used has been presented in the section below.

Simulation Solution

Included below are four different representations of the same data. Each of the plots is obtained as a result of the application of a different setting for the ChartElementFunction    Code

The code for this is done in both Python and Mathematica. They are represented as two distinct blocks.

```from sys import stdout
from mathematica.lists import Range
import csv
from mathematica.sheldon_ross_support_functions import randomChoiceCustom

_csvfile = open(_folderPath + 'sheldon_ross_10_exercise_3.29.csv', 'w', newline='')
_csvWriter = csv.writer(_csvfile)

_steps = 10000
_subSteps = _steps // 100
_masterList = []

print("\n\nWriting data to the file :" + _csvfile.name)

for i in range(0, _steps):
__games = []
for _pA in Range(0.05, 1.00, 0.05):
_probabilities = [_pA, 1 - _pA]
__i = 0
__game = []
while True:
__game.append(randomChoiceCustom(_probabilities[__i % 2]))
__i += 1
if __game[-2:] == [1, 1]:
break
__games.append(__game.__len__())
_csvWriter.writerow(__games)

if (i + 1) % _subSteps == 0:
stdout.write("\r" + ("\r" + ("#" * (i // _subSteps + 1)).ljust(100)) + " " + str(i // _subSteps + 1) + " %")
stdout.flush()

print("Closing the file: " + _csvfile.name)

_csvfile.close()

```
```Needs["JLink`"]
SetOptions[InstallJava, JVMArguments -> "-Xmx8g"];
SetOptions[ReinstallJava, JVMArguments -> "-Xmx8g"];
ReinstallJava[];
SetOptions[\$FrontEndSession,
EvaluationCompletionAction -> {"ScrollToOutput"}]

Column[
Framed[#, FrameStyle -> GrayLevel[0.9]] & /@
Module[{
data = Transpose@Import[FileNames["*.csv", NotebookDirectory[]][]],
chartLabels =
(Rotate[#, Divide[\[Pi], 2] - Divide[\[Pi], 10]]) & /@
(MapThread[("\!\(\*SubscriptBox[\(p\), \(\(\\\ \\)\(A\)\)]\) = " <>
ToString[#1[]] <>
" \!\(\*SubscriptBox[\(p\), \(B\)]\) = " <>
ToString[#1[]]) &, {{#, 1 - #} & /@
Range[0.05, 0.95, 0.05]}]), max = 400},

DistributionChart[data,
ImageSize -> 788,
ChartElementFunction -> #,
GridLines -> {None, Range[25, max, 25]},
FrameLabel -> {{Style["N", 16, Red], ""}, {"", ""}},
ChartLabels -> chartLabels, AspectRatio -> 1,
PlotRange -> {All, {0, max}}] & /@ {"PointDensity", "SmoothDensity", "GlassQuantile", "LineDensity"}
]
]```

End of the post 😀

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.