**Question:** There are three coins in a barrel. These coins, when flipped, will come up heads with respective probabilities 0.3, 0.5, 0.7. A coin is randomly selected from among these three and is then flipped ten times. Let N be the number of heads obtained on the ten flips.

- Find P{N = 0}.
- Find P{N = n}, n = 0, 1, . . . , 10.
- Does N have a binomial distribution?
- If you win $1 each time a head appears and you lose $1 each time a tail appears, is this a fair game? Explain.

**Analytical Solution**

This is an interesting problem for both the simulation and the calculation.

- 1. For the general solution,see the next line
- 2. We will solve the general case and would take care of part 1
- For the problem, simply apply conditional probability theorem and substitute n with the integer (0 thru 10) to get the answer that you need

P{N=n} = P{ N=n|Coin_{A} } * P{ Coin_{A} } + P{ N=n|Coin_{B} } * P{ Coin_{B }} + P{ N=n|Coin_{C} } * P{ Coin_{C }}

P{N=n} = Bimoial[10, n] 0.3^{n} 0.7^{10-n} * ^{1}⁄_{3} + Binomial[10, n] 0.5^{n} 0.5^{10-n} * ^{1}⁄_{3} + Binomial[10, n] 0.7^{n} 0.3^{10-n} * ^{1}⁄_{3}

- 3. Nope since the system becomes a binomial after a previous round of selection
- 4. P{Win} = P{ head($) } = P{ head($)|Coin
_{A}} * P{ Coin_{A}} + P{ head($)|Coin_{B}} * P{ Coin_{B }} + P{ head($)|Coin_{C}} * P{ Coin_{C }}- 0.3 *
^{1}⁄_{3}+ 0.5 *^{1}⁄_{3}+ 0.7 *^{1}⁄_{3}= 0.5

- 0.3 *

**Simulation Solution**

This is a fairly simple simulation give the problem. I have done the Mathematica implementation of this problem. The plots of the parts 2 and 4 are pasted below. The code for the same is also presented in the next section.

**Code**

Module[{outcomesMeta = {}}, Table[Module[{outcomes, turns = 10000}, outcomes = ParallelTable[ Module[{coin := RandomChoice[{0.3, 0.5, 0.7}], coinTemp}, coinTemp = coin; Count[RandomChoice[{coinTemp, 1 - coinTemp} -> {1, 0}, 10], 1]], turns]; outcomes = {#, N@Divide[Count[outcomes, #], turns]} & /@ Range[0, 10]; AppendTo[outcomesMeta, outcomes]; ], 200]; ListLinePlot[outcomesMeta, Frame -> True, ImageSize -> 788, InterpolationOrder -> 2, PlotStyle -> {{PointSize@0.004, Thickness@0, Darker@Green, Opacity@0.1}}, GridLines -> {Range @@ {0, 10, 0.5}, Range @@ {0, 0.2, 0.02}}, FrameTicks -> {Range @@ {0, 10, 1}, Range @@ {0, 0.2, 0.02}}, PlotRange -> {Automatic, {0, 0.2}}, AspectRatio -> 0.5, PlotLabel -> "P{N=n}"] ] Module[{simulation}, simulation = Module[{turns = 10000, coin := RandomChoice[{0.3, 0.5, 0.7}], coinTemp}, Mean /@ ParallelTable[coinTemp = coin; RandomChoice[{coinTemp, 1 - coinTemp} -> {1, 0}], turns, 100] ]; Histogram[simulation, {0.01}, ImageSize -> 788, Frame -> True, GridLines -> None, AspectRatio -> 0.5, PlotLabel -> "Distribution of : P{X=heads} or P{X=$$$}"] ]

End of the post 😉

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.