Twenty-four Problems from Ars Conjectandi

Oleksandr Pavlyk, Mathematica Algorithm R&D, Wolfram Research, Inc., 
Jan. 15, 2015

Problem I

Statement

Three people, A, B, and C, play a game where they take turns drawing with replacement from an urn containing equal numbers of black balls and white balls. Each person draws once in the order A, B, and then C. The first person, if any, to draw a white ball wins; otherwise, nobody wins. Compute their chances at winning the game.

Solution

Indicator random variables, equaling 1 if a white ball is drawn and 0 if black, follow the Bernoulli distribution with success probability equal to 1/2:

pA=Probability[aw==1,{aw,bw,cw}\[Distributed]ProductDistribution[{BernoulliDistribution[1/2],3}]]

pB=Probability[aw==0&&bw==1,{aw,bw,cw}\[Distributed]ProductDistribution[{BernoulliDistribution[1/2],3}]]

pC=Probability[aw==0&&bw==0&&cw==1,{aw,bw,cw}\[Distributed]ProductDistribution[{BernoulliDistribution[1/2],3}]]

pNone=Probability[aw==0&&bw==0&&cw==0,{aw,bw,cw}\[Distributed]ProductDistribution[{BernoulliDistribution[1/2],3}]]

ToProportions[{pA,pB,pC}]

Problem 2

Statement

Three people, A, B, and C, play a game where they take turns drawing with replacement from an urn containing equal numbers of black balls and white balls. Each person draws once in the order A, B, and then C. The first person, if any, to draw a white ball wins and claims a prize; otherwise, the prize is shared equally. Compute their chances at winning the game.

Solution

pA=Expectation[Boole[aw==1]+Boole[aw==bw==cw==0]/3,{aw,bw,cw}\[Distributed]ProductDistribution[{BernoulliDistribution[1/2],3}]]

pB=Expectation[Boole[aw==0&&bw==1]+Boole[aw==bw==cw==0]/3,{aw,bw,cw}\[Distributed]ProductDistribution[{BernoulliDistribution[1/2],3}]]

pC=Expectation[Boole[aw==0&&bw==0&&cw==1]+Boole[aw==bw==cw==0]/3,{aw,bw,cw}\[Distributed]ProductDistribution[{BernoulliDistribution[1/2],3}]]

ToProportions[{pA,pB,pC}]

Problem 3

Statement

Six players, A, B, C, D, E, and F—as ordered by the organizer, who favors the later players—attempt a game of chance. First A plays against B. The winner plays with C, then that winner plays with D, and so forth until the last player, F. The winner of the last game gets the prize. Assuming that in each game players have an equal chance of winning, determine that their odds of winning the prize are 1∷1∷2∷4∷8∷16.

Solution

We enumerate outcomes of these five games with 5-tuples of 0 if the first player wins and 1 if the second wins, which represent binary digits of integers from 0 through 31:

signatureToProbabilitySequence[tpl_]:=Table[1/2,{tpl}]

signatureToWinnerSequence[tpl_List]:=Block[{cv=1,cont=1},
Rest[FoldList[(++cont;If[#2==1,#1,cont])&,cv,tpl]]
]

The complete binary tree of all outcomes looks as follows:

gr=CompleteKaryTree[6,DirectedEdges->True];
spf=FindShortestPath[gr,1,All];
gameGraph=SetProperty[gr,{VertexLabels->Union[Join @@ Table[Thread[Rest[spf[(2^6)-k]]->Map[Part[CharacterRange["A","F"],#]&,signatureToWinnerSequence[IntegerDigits[k-1,2,5]]]],{k,2^5}]],VertexSize->Medium,
VertexStyle->Table[Last[spf[(2^6)-k]]->Directive[Large,ColorData[1,Last[signatureToWinnerSequence[IntegerDigits[k-1,2,5]]]]],{k,2^5}],
Properties->Join @@ Table[Thread[(DirectedEdge @@@Partition[spf[(2^6)-k],2,1])->({Probability->#}&/@signatureToProbabilitySequence[IntegerDigits[k-1,2,5]])],{k,2^5}],GraphLayout->"RadialEmbedding"}]

Enumerate the leaves of the tree, showing winners and the probability of this outcome, which are all equal to (((1/2))^5):

wp=Table[{Part[CharacterRange["A","F"],#]&[Last[signatureToWinnerSequence[IntegerDigits[k,2,5]]]],
Times@@signatureToProbabilitySequence[IntegerDigits[k,2,5]]},{k,0,2^5-1}]

Now group outcomes by winners and total their probabilities of winning the game:

probs=KeySort[GroupBy[wp,First->Last,Total]]

ToProportions[probs]

Problem 4

Statement

Six people participate in a play consisting of five successive games. In the first game, (Subscript[A, 1]) plays against (Subscript[A, 2]). The winner plays against (Subscript[A, 3]) in the second game, and so on, until the winner of the fourth game plays against (Subscript[A, 6]) in the last game. 

After the first game, where the chances of winning are equal for (Subscript[A, 1]) and (Subscript[A, 2]), any player playing against his second opponent has odds of 2∷1 of winning, against his third opponent 4∷1, and so on.

Prove that the odds of winning for the six participants are 7680∷7680∷5440∷4488∷4250∷4887.

Solution

It is much the same as the previous problem, except the probabilities of each game are now not constant:

signatureToProbabilitySequence[sign_]:=Block[{victoriesCount=0,chance},
Table[chance=2^victoriesCount;If[bit==0,victoriesCount=1,++victoriesCount];{(1/(chance+1)),(chance/(chance+1))}[[bit+1]],{bit,sign}]
]

signatureToWinnerSequence[sign_List]:=Block[{cv=1,cont=1},
Rest[FoldList[(++cont;If[#2==1,#1,cont])&,cv,sign]]
]

gr=CompleteKaryTree[6,DirectedEdges->True];spf=FindShortestPath[gr,1,All];
gameGraph=SetProperty[gr,{VertexLabels->Union[Join @@ Table[Thread[Rest[spf[(2^6)-k]]->Map[(Subscript[A, #])&,signatureToWinnerSequence[IntegerDigits[k-1,2,5]]]],{k,2^5}]],VertexSize->Medium,
VertexStyle->Table[Last[spf[(2^6)-k]]->Directive[Large,ColorData[1,Last[signatureToWinnerSequence[IntegerDigits[k-1,2,5]]]]],{k,2^5}],
Properties->Join @@ Table[Thread[(DirectedEdge @@@Partition[spf[(2^6)-k],2,1])->({Probability->#}&/@signatureToProbabilitySequence[IntegerDigits[k-1,2,5]])],{k,2^5}],GraphLayout->"RadialEmbedding"}]

wp=Table[{(Subscript[A, #])&[Last[signatureToWinnerSequence[IntegerDigits[k-1,2,5]]]],
Times@@signatureToProbabilitySequence[IntegerDigits[k-1,2,5]]},{k,2^5}]

probs=KeySort[GroupBy[wp,First->Last,Total]]

ToProportions[probs]

Problem 5

Statement

Player A contends with player B that four randomly selected cards from a pack of forty cards, with ten of each suit, will contain a card of each suit. Find that the odds of A winning the game are 1000∷8139.

Solution

The number of cards of each suit among the four cards dealt follow multivariate hypergeometric distribution:

pA=Probability[{n♢,n♣,n♡,n♠}=={1,1,1,1},{n♢,n♣,n♡,n♠}\[Distributed]MultivariateHypergeometricDistribution[4,{10,10,10,10}]]

ToProportions[{pA,1-pA}]

Problem 6

Statement

Player A contends with player B that randomly drawing seven balls from an urn containing four white balls and eight black balls without replacement will give player A three white balls. Establish that A’s odds of winning the bet are 35 : : 64.

Solution

The number of white balls in the sample follow hypergeometric distribution:

pA=Probability[nw==3,nw\[Distributed]HypergeometricDistribution[7,4,4+8]]

ToProportions[{pA,1-pA}]

Problem 7

Statement

Some number of players, (Subscript[A, 1]), (Subscript[A, 2]), (Subscript[A, 3]), etc., draw cards in order and alternately from a hand of playing cards, of which one is a face card and the rest are non-face cards. The person who draws the face card wins. Assuming that (Subscript[A, 1]) draws first, what is the ratio of their lots?

Solution

Let there be n players and m cards, with m≥n. The problem is equivalent to the one where one randomly chooses a winner from the sequence of players of length m. If m==p n+q, the first q players will draw p+1 times, and the remaining n-q players will draw p times.

For example, of n==5 and m==52, probabilities of winning are:

With[{n=5,m=52},pvec=Table[PDF[MultivariateHypergeometricDistribution[1,Table[Quotient[m+n-k,n],{k,n}]],UnitVector[n,k]],{k,1,n}]]

ToProportions[pvec]

Problem 8

Statement

Some number of players, (Subscript[A, 1]), (Subscript[A, 2]), (Subscript[A, 3]), etc., draw cards in order and alternately from a hand of playing cards, of which several cards are face cards and the rest are non-face cards. The person who first draws the face card wins. Assuming that (Subscript[A, 1]) draws first, what is the ratio of their lots?

Solution

Let there be n players and m cards, with m≥n, among which f are face cards.

Simulation, where the first f cards are assumed to be face cards:

#/Total[#]&[With[{n=3,m=9,f=2},
Counts[Mod[First[Pick[Range[m],FactorialPower[#-1,f],0]],3,1]&/@Permutations[Range[m]]]
]]

Assuming the winner is the player (Subscript[A, p]), he might have won in the first round, or in the second, and so on. These events are disjoint, so that their probabilities are added:

With[{n=3,m=9,f=2},
Table[Sum[Probability[{fc0,fc1}=={0,1},{fc0\[Distributed]HypergeometricDistribution[q n+p-1,f,m],fc1\[Distributed]HypergeometricDistribution[1,f,m-(q n+p)+1]}],{q,0,Quotient[m-p+1-f,n]}],{p,1,n}]]

In the case of three players, with a pack of 52 cards with 12 face cards, the odds are strongly in favor of the first player:

With[{n=3,m=52,f=12},
Table[Sum[Probability[{fc0,fc1}=={0,1},{fc0\[Distributed]HypergeometricDistribution[q n+p-1,f,m],fc1\[Distributed]HypergeometricDistribution[1,f,m-(q n+p)+1]}],{q,0,Quotient[m-p+1-f,n]}],{p,1,n}]]

ToProportions[%]

N[%%]

Problem 9

Statement

Some number of players, (Subscript[A, 1]), (Subscript[A, 2]), (Subscript[A, 3]), etc., draw cards in order and alternately from a hand of playing cards, of which several cards are face cards and the rest are non-face cards. The person who draws more face cards will win, and if two or more players draw an equal number of face cards, they will divide the stake equally among them. Find the ratio of their lots.

Solution

Define the payout function, giving the payout to a player who has c1 face cards, given the vector with amounts of face cards for the remaining players:

payoutFunction[c1_,re:{crest__}]:=With[{len=Length[re]},Boole[c1>Max[crest]]+Sum[(1/(k+1))Boole[c1==Max[re]==RankedMax[re,k]&&c1>RankedMax[re,k+1]],{k,len-1}]+(1/(1+len))Boole[Equal[c1,crest]]]

For example, for two players, with c1 and c2 face cards respectively, payouts are:

{payoutFunction[c1,{c2}],payoutFunction[c2,{c1}]}

Counts of face cards obtained by each player follow multivariate hypergeometric distribution.

Bernoulli considers the case of 20 cards with 10 face cards among them, and 3 players:

With[{n=3,m=20,f=10},Table[
Expectation[payoutFunction[𝓃[q],Delete[Array[𝓃,n],q]],{Array[𝓃,n]\[Distributed]MultivariateHypergeometricDistribution[f,Table[Quotient[m+n-k,n],{k,n}]]}]
,{q,n}]]

ToProportions[%]

Problem 10

Statement

Four players, (Subscript[A, 1]), (Subscript[A, 2]), (Subscript[A, 3]), and (Subscript[A, 4]), draw cards in order and alternately from a hand of 36 playing cards, of which 16 cards are face cards. After 23 cards have been drawn, (Subscript[A, 1]) has received four face cards; (Subscript[A, 2]), three; (Subscript[A, 3]), two; and (Subscript[A, 4]), one. Player (Subscript[A, 4]), whose turn is next, wishes to sell his rights to the stake to one of the other players. How much should he sell them for, and what are the expectations of the individual players?

Solution

This is like the previous problem:

payoutFunction[cw_,re:{crest__}]:=Block[{n=Length[re]},Boole[cw>Max[crest]]+Sum[(1/(k+1))Boole[cw==Max[re]==RankedMax[re,k]&&cw>RankedMax[re,k+1]],{k,n-1}]+(1/(1+n))Boole[Equal[cw,crest]]]

With[{n=4,m=36,f=16,𝓃vec={4,3,2,1},m0=23},Table[
Expectation[payoutFunction[𝓃[q],Delete[Array[𝓃,n],q]],{Array[𝓃,n]\[Distributed]TransformedDistribution[Array[𝓃0,n]+𝓃vec,
Array[𝓃0,n]\[Distributed]MultivariateHypergeometricDistribution[f-Total[𝓃vec],Table[Quotient[(m-m0)+n-Mod[k-Mod[m0,n],n,1],n],{k,1,n}]]]}]
,{q,n}]]

ToProportions[%]

Hence the fair price for his rights is 21/1144 of the value at stake.

Problem 11

Statement

Compute the probability that with a throw of six six-sided dice, each face will appear once.

Solution

Of (6^6) possible equally likely outcomes, 6! have each face occur just once:

Probability[Unequal[x1,x2,x3,x4,x5,x6],{x1,x2,x3,x4,x5,x6}\[Distributed]DiscreteUniformDistribution[Table[{1,6},{6}]]]

%==((6!)/(6^6))

Problem 12

Statement

Compute the probability that with six throws of a six-sided dice, the sequence of scores will be {1,2,3,4,5,6}.

Solution

Of (6^6) possible outcomes, there is one configuration of interest:

Probability[{x1,x2,x3,x4,x5,x6}=={1,2,3,4,5,6},{x1,x2,x3,x4,x5,x6}\[Distributed]DiscreteUniformDistribution[Table[{1,6},{6}]]]

%==1/(6^6)

Problem 13

Statement

Three players, A, B, and C, each having written in front of himself the first six numerals, play with a die alternately, on the condition that whoever throws any number of points deletes that number from his written numbers, or, if he does not have that number anymore, the following player proceeds to throw. This continues until someone first deletes all his written numerals. It happens, however, that after the game has been played for a while, A still has two numbers before him, B has four, C has three, and it is A’s turn to throw. What are their lots?

Solution

Bernoulli writes, “This problem requires more labor and patience than ingenuity.” In fact, he does not solve the problem completely, saying, “But the whole calculation is for a person of abundant leisure. We, being busier, will go on to other things.”

Denote the state of the game as 𝒮[turn,{nA,nB,nC}], and let’s build the state transition graph with respective probabilities:

oneCycleTransitions[nA_,nB_,nC_]:={
Property[𝒮["A",{nA,nB,nC}]\[DirectedEdge]If[nA==1,𝒮["A wins"],𝒮["B",{nA-1,nB,nC}]],Probability->(nA/6)],Property[𝒮["A",{nA,nB,nC}]\[DirectedEdge]𝒮["B",{nA,nB,nC}],Probability->1-(nA/6)],
Property[𝒮["B",{nA,nB,nC}]\[DirectedEdge]If[nB==1,𝒮["B wins"],𝒮["C",{nA,nB-1,nC}]],Probability->(nB/6)],Property[𝒮["B",{nA,nB,nC}]\[DirectedEdge]𝒮["C",{nA,nB,nC}],Probability->1-(nB/6)],Property[𝒮["C",{nA,nB,nC}]\[DirectedEdge]If[nC==1,𝒮["C wins"],𝒮["A",{nA,nB,nC-1}]],Probability->(nC/6)],
Property[𝒮["C",{nA,nB,nC}]\[DirectedEdge]𝒮["A",{nA,nB,nC}],Probability->1-(nC/6)]};

winnerTransitions={Property[𝒮["A wins"]\[DirectedEdge]𝒮["A wins"],Probability->1],Property[𝒮["B wins"]\[DirectedEdge]𝒮["B wins"],Probability->1],
Property[𝒮["C wins"]\[DirectedEdge]𝒮["C wins"],Probability->1]};

gr=Graph[Flatten[Table[oneCycleTransitions[nA,nB,nC],{nA,2},{nB,4},{nC,3}]]~Join~winnerTransitions]

Now we use the graph to build a Markov chain describing the game:

gameMP=DiscreteMarkovProcess[VertexIndex[gr,𝒮["A",{2,4,3}]],WeightedAdjacencyMatrix[gr,EdgeWeight->Probability]];

Because one of the players will certainly erase all the numerals in front of him/her first, the stationary distribution of the Markov chain will show probabilities with which each player might win the game:

stdist=StationaryDistribution[gameMP];

victoryChances=PDF[stdist,VertexIndex[gr,#]&/@{𝒮["A wins"],𝒮["B wins"],𝒮["C wins"]}]

N[victoryChances]

Simulation:

simCF=Compile[{{turn,_Integer},{nA,_Integer},{nB,_Integer},{nC,_Integer}},
Module[{cA=nA,cB=nB,cC=nC,d,cturn=turn},
While[True,
d=RandomInteger[{1,6}];
Which[
cturn===1,If[d≤cA,If[(--cA)==0,Return[cturn]]],
cturn===2,If[d≤cB,If[(--cB)==0,Return[cturn]]],
cturn===3,If[d≤cC,If[(--cC)==0,Return[cturn]]]];
cturn=1+Mod[cturn,3];
];
cturn
]];

Simulation is in agreement with exact computation:

#/Total[#]&[KeySort[Counts[Table[simCF[1,2,4,3],{2^22}]]]//N]

Problem 14

Statement

Two players, A and B, throw a die whose score determines the total number of throws each player makes. The person with the higher total score claims the stake, or the stake is equally divided in case of a tie. One of the players, B, proposes to take 12 points as his score, instead of throwing the die. Player A agrees. What are the lots of each player?

Solution

Bernoulli notes the ambiguity in whether the first throw is counted toward the total number of throws player A makes.

Assuming the first throw of the die does not count toward player A’s throws:

pA=Expectation[Boole[x>12]+(1/2)Boole[x==12],x\[Distributed]MixtureDistribution[Table[(1/6),{6}],
Table[TransformedDistribution[(∑_(i=1)^n)(Subscript[d, i]),Table[(Subscript[d, i])\[Distributed]DiscreteUniformDistribution[{1,6}],{i,n}]],{n,6}]]]

N[pA]

ToProportions[{pA,1-pA}]

Assuming the first throw of the die does count toward his throws:

pA=Expectation[Boole[x>12]+(1/2)Boole[x==12],x\[Distributed]MixtureDistribution[Table[(1/6),{6}],
Table[TransformedDistribution[n+(∑_(i=2)^n)(Subscript[d, i]),Table[(Subscript[d, i])\[Distributed]DiscreteUniformDistribution[{1,6}],{i,n}]],{n,6}]]]

N[pA]

ToProportions[{pA,1-pA}]

Problem 15

Statement

Two players, A and B, throw a die whose score determines the total number of throws each player makes. The person with the higher total score claims the stake, or the stake is equally divided in case of a tie. One of the players, B, proposes to take the square of the number of points on the first throw as his score, instead of throwing dice. Player A agrees. What are the lots of each player?

Solution

Assuming the first throw of the die does not count toward player A’s throws:

pA=Expectation[Boole[xA>xB]+(1/2)Boole[xA==xB],{xA,xB}\[Distributed]MixtureDistribution[Table[(1/6),{6}],
Table[TransformedDistribution[{(∑_(i=1)^n)(Subscript[d, i]),(n^2)},Table[(Subscript[d, i])\[Distributed]DiscreteUniformDistribution[{1,6}],{i,n}]],{n,6}]]]

N[pA]

ToProportions[{pA,1-pA}]

Assuming the first throw of the die does count toward his throws:

pA=Expectation[Boole[xA>xB]+(1/2)Boole[xA==xB],{xA,xB}\[Distributed]MixtureDistribution[Table[(1/6),{6}],
Table[TransformedDistribution[{n+(∑_(i=2)^n)(Subscript[d, i]),(n^2)},Table[(Subscript[d, i])\[Distributed]DiscreteUniformDistribution[{1,6}],{i,n}]],{n,6}]]]

N[pA]

ToProportions[{pA,1-pA}]

Problem 16

Statement

This game, called “Five and Nine,” is played by two people, A and B, with two dice. Player A always throws the dice. 
	• If A on the first turns throws a 3 or an 11 or any doubles, then A wins. 
	• If A throws a 5 or a 9, player B wins. 
	• If A throws any other number of points, namely 4, 6, 7, 8, or 10, then neither of the players wins and the game continues until a 5 or a 9 is thrown, in which case B is always a winner, or until exactly the same number of points is thrown again as was thrown on the first throw, in which case A wins.

What is the ratio of their lots?

Solution

diceDist={d1\[Distributed]DiscreteUniformDistribution[{1,6}],d2\[Distributed]DiscreteUniformDistribution[{1,6}]};

Conditions for winning on the first throw:

AwinsFirstThrow=d1==d2||d1+d2==3||d1+d2==11;
BwinsFirstThrow=d1+d2==5||d1+d2==9;

The probability that the total score from throwing two dice is equal to a given score is as follows:

pA2[score_]=Probability[d1+d2==score,diceDist]

The probability of getting 5 or 9 on the subsequent throws is the same as on the first throw:

pB2=Probability[d1+d2==5||d1+d2==9,diceDist]

pGameContinues2[score_]=(1-pA2[score]-pB2)

Player A wins on the (n+1)th turn if n previous turns did not determine the winner, and if the score equals the score of the first throw:

pA=Expectation[Piecewise[{{1,AwinsFirstThrow},{0,BwinsFirstThrow}},Sum[((pGameContinues2[d1+d2])^(n-2))pA2[d1+d2],{n,2,Infinity}]],diceDist]

pB=Expectation[Piecewise[{{0,AwinsFirstThrow},{1,BwinsFirstThrow}},Sum[ ((pGameContinues2[d1+d2])^(k-2))pB2,{k,2,Infinity}]],diceDist]

pA+pB

{pA,pB}//N

ToProportions[{pA,pB}]

Simulation:

cfFiveAndNine=Compile[{},
Module[{s1,d1,d2,s},
d1=RandomInteger[{1,6}];d2=RandomInteger[{1,6}];
s1=d1+d2;
If[(s1-5)(s1-9)==0,Return[2]];
If[(s1-3)(s1-11)(d1-d2)==0,Return[1]];
While[True,
d1=RandomInteger[{1,6}];d2=RandomInteger[{1,6}];s=d1+d2;
If[s==s1,Return[1]];
If[(s-5)(s-9)==0,Return[2]];
];
1
]];

#/Total[#]&[Table[cfFiveAndNine[],{10^8}]//Counts//KeySort//KeyMap[Part[{"A","B"},#]&,#]&]//N

Problem 17

Statement

A pitchman attracts shoppers at the weekly market to play the following game of chance.

The border of a circular disk, mounting a little upwards toward the center, is surrounded by 32 contiguous identical openings that are marked into four distinct classes by the numbers written four times from 1 to 8. Balls can be dropped on the center of the disk through a funnel.

The player pays four coins and drops four little balls through the funnel, one at a time, which end up in four openings in the circumference of the disk. The sum of the numbers from corresponding openings determine the prize won, according to the table below.

What is the player’s expectation?

winningTable=AssociationThread[Range[4,32],{120,100,30,24,18,10,6,6,6,5,3,3,3,2,2,3,3,3,3,4,4,6,8,12,16,24,25,32,180}]

Solution

winning[p_Integer]:=winningTable[p]

The number of balls that landed in openings numbered 1 through 8 follow multivariate hypergeometric distribution:

playerExpectedWinning=Expectation[winning[{n1,n2,n3,n4,n5,n6,n7,n8}.Range[8]],{n1,n2,n3,n4,n5,n6,n7,n8}\[Distributed]MultivariateHypergeometricDistribution[4,Table[4,{8}]]]-4

The organizer of the game is going bankrupt in the long run, but a player is more likely to lose money in a single game:

probOfGaining=Probability[winning[{n1,n2,n3,n4,n5,n6,n7,n8}.Range[8]]>4,{n1,n2,n3,n4,n5,n6,n7,n8}\[Distributed]MultivariateHypergeometricDistribution[4,Table[4,{8}]]]

probOfLoosing=Probability[winning[{n1,n2,n3,n4,n5,n6,n7,n8}.Range[8]]<4,{n1,n2,n3,n4,n5,n6,n7,n8}\[Distributed]MultivariateHypergeometricDistribution[4,Table[4,{8}]]]

probOfBreakingEqual=Probability[winning[{n1,n2,n3,n4,n5,n6,n7,n8}.Range[8]]==4,{n1,n2,n3,n4,n5,n6,n7,n8}\[Distributed]MultivariateHypergeometricDistribution[4,Table[4,{8}]]]

{probOfGaining,probOfLoosing,probOfBreakingEqual}//N

Simulated payouts in 25 games:

ListPlot[(winning/@RandomVariate[TransformedDistribution[{n1,n2,n3,n4,n5,n6,n7,n8}.Range[8],{n1,n2,n3,n4,n5,n6,n7,n8}\[Distributed]MultivariateHypergeometricDistribution[4,Table[4,{8}]]],25]),Epilog->{Gray,Dashed,Line[{{1,4},{30,4}}]},Filling->Axis,Ticks->{Automatic,Range[Min[winningTable],Max[winningTable]]}]

Problem 18

Statement

This game is called “Three Jacks.”

Bernoulli discusses the game of “Three Jacks,” which is similar to stud poker. He asks to estimate the chances of winning, given a good hand of hole cards.

This problem, being too tedious to even describe, is being skipped.

Problem 19

Statement

Consider a game in which the organizer, the banker of the game, has some advantage over the other player, but can lose the office in some uncommon situations. Assuming the banker is more likely to keep the office than to transfer it to the other player, how great is the advantage of the banker?

Solution

Conditional on the first player being a banker, his odds of winning are 𝓅∷𝓆. His odds of retaining the office against losing it to the other player is 𝓂∷𝓃. Upon winning, the loser pays one unit of his money to the winner.

Transitions of the office between players is described by a two-state Markov chain, whereas payouts, conditional on being in a particular state, are described by Bernoulli distributions. The payouts thus follow a hidden Markov process with two states and two emissions.

After playing m games, and assuming a large enough initial capital at each player’s disposal, the expected net profit of the player that started as a banker equals:

expectedFortune1=Sum[Expectation[Boole[x[t]==2]-Boole[x[t]==1],x\[Distributed]HiddenMarkovProcess[1,{{(𝓂/(𝓂+𝓃)),(𝓃/(𝓂+𝓃))},{(𝓃/(𝓂+𝓃)),(𝓂/(𝓂+𝓃))}},{{(𝓆/(𝓅+𝓆)),(𝓅/(𝓅+𝓆))},{(𝓅/(𝓅+𝓆)),(𝓆/(𝓅+𝓆))}}]],{t,0,m-1}]

Limit[expectedFortune1,m->Infinity,Assumptions->𝓅>𝓆>0&&𝓂>𝓃>0]

Problem 20

Statement

Bernoulli analyzes the card game of Bock.

One player is chosen as banker. He shuffles the cards and selects as many cards as there are players. Each player chooses a card for a fixed price 𝒫 paid to the banker, leaving the last card to the banker.

Finally the banker reveals each card. The banker pays those whose cards are of a higher rank than his the amount 𝒫, but those whose cards are of lesser or equal rank forfeit their payment to the banker.

The banker remains in the office unless he has been bested by absolutely all his fellow players.

Find the lot of the banker.

Solution

This problem is a particular case of the scheme, considered in problem 19. Hence, we only need to determine the expected winning of the banker, and the probability that he retains the office.

Suppose the deck of cards has 𝓇 ranks and 𝓈 suits, i.e. the deck contains the total of 𝓇 𝓈 cards. Suppose there are p players.

Let (Subscript[n, k]) be the number of cards of the face value (Subscript[v, k]), such that (Subscript[v, 1])<(Subscript[v, 2])<…<(Subscript[v, r]). Let nvec=={(Subscript[n, 1]),…,(Subscript[n, r])}. Suppose the banker has the card of face value (Subscript[v, k]), in which case he collects ((Subscript[n, k])-1+(∑_(m=k+1)^r)(Subscript[n, m])). The probability of the banker getting this card equals (Subscript[ω, k])==(Subscript[n, k])/(∑_(m=1)^r)(Subscript[n, m])==(Subscript[n, k])/p.

Therefore, the banker's expected winnings conditional on such a configuration equals:

(∑_(k=1)^r)((Subscript[n, k])/p)((Subscript[n, k])-1+(∑_(m>k))(Subscript[n, m]))==(1/p)((∑_(k=1)^r)((Subscript[n, k])^2)-p+(∑_(k=1)^r)(∑_(m=1)^r)Boole[m>k](Subscript[n, k])(Subscript[n, m]))==(1/p)((∑_(k=1)^r)((Subscript[n, k])^2)-p+(1/2)(∑_(k=1)^r)(∑_(m=1)^r)Boole[m!=k](Subscript[n, k])(Subscript[n, m]))==(1/p)((∑_(k=1)^r)((Subscript[n, k])^2)-p+(1/2)((((∑_(k=1)^r)(Subscript[n, k])))^2)-(1/2)(∑_(k=1)^r)(((Subscript[n, k])^2)))==(1/p)((1/2)(∑_(k=1)^r)((Subscript[n, k])^2)-p+(1/2)(p^2))

bankerWinnings[p_,nvec_List]:=Divide[p-2,2]+Divide[Total[nvec^2],2p]

Expectation of the banker’s winning is easy to find, since {(Subscript[n, 1]),…,(Subscript[n, r])} follows multivariate hypergeometric distribution, and each individual count (Subscript[n, k]) follows HypergeometricDistribution[p,𝓈,𝓈 𝓇]:

bankerExpectedWinning=((p-2)/2)+(𝓇/(2p))Moment[HypergeometricDistribution[p,𝓈,𝓇 𝓈],2]//FullSimplify

contendersExpectedWinning=Together[p-1-bankerExpectedWinning]

Check for explicit values of ranks, suits, and players:

Block[{𝓇=7,𝓈=4,p=4},{Expectation[bankerWinnings[p,Array[n,𝓇]],Array[n,𝓇]\[Distributed]MultivariateHypergeometricDistribution[p,Table[𝓈,{𝓇}]]],bankerExpectedWinning}]

The banker leaves the office when he is bested by all the players, which happens if there is only one lowest-value card and the banker has it, which happens with probability of 1/p.

The conditional probability that the banker stays in the office equals 1-(1/p)(Boole[(Subscript[n, 1])==1]+Boole[(Subscript[n, 1])==0&&(Subscript[n, 2])==1]+Boole[(Subscript[n, 1])==0&&(Subscript[n, 2])==0&&(Subscript[n, 3])==1]+…):

bankerKeepsOffice[p_,nvec_List]:=1-(1/p)Sum[Boole[Take[nvec,k]==UnitVector[k,k]],{k,Length[nvec]}]

Probability that the banker keeps the office:

Pr[KeepingOffice]==(1-(1/p))Pr[event]+1 (1-Pr[event])==1-Pr[event]/p

Because the vector {(Subscript[n, 1])+…+(Subscript[n, k-1]),(Subscript[n, k]),(Subscript[n, k+1])+…+(Subscript[n, r])} also follows multivariate hypergeometric distribution, the probability of the event of interest equals:

Pr[event]==(∑_(k=1)^(r-1))PDF[MultivariateHypergeometricDistribution[p,{(k-1)𝓈,𝓈,(𝓇-k)𝓈}],{0,1,𝓇-1}]==(𝓈/(Binomial[𝓇 𝓈,p]))Sum[Binomial[k 𝓈,p-1],{k,1,𝓇-1}]

Check for explicit values of ranks, suits, and players:

With[{𝓇=7,𝓈=4,p=3},{Expectation[bankerKeepsOffice[p,Array[n,𝓇]],Array[n,𝓇]\[Distributed]MultivariateHypergeometricDistribution[p,Table[𝓈,{𝓇}]]],1-(1/p)(𝓈/(Binomial[𝓇 𝓈,p]))Sum[Binomial[k 𝓈,p-1],{k,1,𝓇-1}]}]

In the case of two players, the probabilities of losing and of keeping the office are, as found by Bernoulli:

With[{p=2},{1-(𝓈/(Binomial[𝓇 𝓈,p]))Sum[Binomial[k 𝓈,p-1],{k,1,𝓇-1}]/p,(𝓈/(Binomial[𝓇 𝓈,p]))Sum[Binomial[k 𝓈,p-1],{k,1,𝓇-1}]/p}//Together]

Bernoulli also considers the case of three players, in the case of four suits:

With[{p=3,𝓈=4},{1-(𝓈/(Binomial[𝓇 𝓈,p]))Sum[Binomial[k 𝓈,p-1],{k,1,𝓇-1}]/p,(𝓈/(Binomial[𝓇 𝓈,p]))Sum[Binomial[k 𝓈,p-1],{k,1,𝓇-1}]/p}//Together]//FullSimplify//ExpandNumerator

Problem 21

Statement

On the game of Basset:

Consider a pack of 2n cards, of which k are marked A and 2n-k are marked B.

Drawing two cards successively without replacement, the four possible outcomes are AB, BA, AA, and BB. In cases AB and AA, the banker wins one coin from the gambler. In the case of BA, the banker loses one coin to the gambler. In the case of BB, the game continues and the banker draws another pair of cards from the pack.

Furthermore, should BA be the last pair of cards drawn, then the advantage of the gambler is null (i.e. the banker pays nothing), and should AB or AA be the first pair drawn from the pack, the banker only collects 2/3 from the gambler.

Find the expected winning of the banker.

Solution

Probabilities of the four possible drawings of two cards:

pAA[n2_,k_]:=(k/n2)((k-1)/(n2-1))
pAB[n2_,k_]:=(k/n2)((n2-k)/(n2-1))
pBA[n2_,k_]:=((n2-k)/n2)(k/(n2-1))
pBB[n2_,k_]:=((n2-k)/n2)((n2-k-1)/(n2-1))

pAA[2n,k]+pAB[2n,k]+pBA[2n,k]+pBB[2n,k]//FullSimplify

No amendments

gain[{"A","A"}]:=1
gain[{"A","B"}]:=1
gain[{"B","A"}]:=-1
gain[{"B","B"}]:=0

gameGain[pairs_]:=Sum[gain[pair],{pair,pairs}]

Computation by enumeration:

Clear[eExpectedBankerWinning];eExpectedBankerWinning[n_Integer,k_Integer]:=Block[{vec=PadRight[ConstantArray["A",k],2n,"B"]},Mean[gameGain[Partition[#,2]]&/@Permutations[vec]]]

eExpectedBankerWinning[5,3]

Conditioning on the next draw, it is easy to establish a recurrence equation for the expected winning with n pairs of cards remaining in the pack, of which k are marked:

winning[n,k]==pAA[2n,k](1+winning[n-1,k-2])+pAB[2n,k](1+winning[n-1,k-1])+pBA[2n,k](-1+winning[n-1,k-1])+pBB[2n,k]winning[n-1,k]

rExpectedBankerWinning[𝓃_Integer,𝓀_Integer]/;2𝓃≥𝓀≥0:=Block[{winning},
winning[n_,0]:=0;
winning[n_Integer?Positive,k_Integer?Positive]:=winning[n,k]=Block[{w},Expand[pAA[2n,k](1+w[n-1,k-2])+pAB[2n,k](1+w[n-1,k-1])+pBA[2n,k](-1+w[n-1,k-1])+pBB[2n,k] w[n-1,k]]/.w->winning];

winning[𝓃,𝓀]
]

Confirm that the winning determined by the recurrence relation agrees with the one obtained by enumeration:

Table[eExpectedBankerWinning[n,k]==rExpectedBankerWinning[n,k],{k,1,3},{n,2k,2k+4}]

DiscretePlot[rExpectedBankerWinning[n,n],{n,1,14}]

Now use FindSequenceFunction to guess the closed-form expression for the expected winning:

Table[FindSequenceFunction[Table[{n,rExpectedBankerWinning[n,k]},{n,Quotient[k+1,2],Quotient[k+1,2]+12}],𝓃]//Simplify,{k,1,12}]

FindSequenceFunction[%,𝓀]

Confirm that the recurrence relation is satisfied:

𝓌[n,k]==pAA[2n,k](1+𝓌[n-1,k-2])+pAB[2n,k](1+𝓌[n-1,k-1])+pBA[2n,k](-1+𝓌[n-1,k-1])+pBB[2n,k]𝓌[n-1,k]/.𝓌[𝓃_,𝓀_]:>(((-1+𝓀) 𝓀)/(2 (-1+2 𝓃)))//Simplify

Amendments

The following amendments are now accounted for:

• The first pair with the first marked card only yields 2/3 of the gain
• The last BA pair is null (no payout to the gambler)

gameGainAmended[{p:{f_,l_}}]:=Clip[gain[p],{0,2/3}];
gameGainAmended[pairs_]/;Length[pairs]>1:=Clip[gain[First[pairs]],{-1,2/3}]+Sum[gain[pair],{pair,Take[pairs,{2,-2}]}]+Clip[gain[Last[pairs]],{0,1}]

Clear[eExpectedBankerWinningWithAmendments];
eExpectedBankerWinningWithAmendments[n_Integer,k_Integer]/;2n≥k≥0:=Block[{vec=PadRight[ConstantArray["A",k],2n,"B"]},Mean[gameGainAmended[Partition[#,2]]&/@Permutations[vec]]]

The recurrence is similarly defined, save for the boundary cases:

Clear[rExpectedBankerWinningWithAmendments];
rExpectedBankerWinningWithAmendments[𝓃_Integer,𝓀_Integer]/;2𝓃≥𝓀≥0:=Block[{winning},
winning[n_,0]:=0;
winning[n_Integer?Positive,k_Integer?Positive]:=winning[n,k]=Block[{w},Expand[pAA[2n,k](1+w[n-1,k-2])+pAB[2n,k](1+w[n-1,k-1])+pBA[2n,k](If[n==1&&k==1,0,-1]+w[n-1,k-1])+pBB[2n,k] w[n-1,k]]/.w->winning];

pAA[2𝓃,𝓀]((2/3)+winningAmendedRecursion[𝓃-1,𝓀-2])+pAB[2𝓃,𝓀]((2/3)+winningAmendedRecursion[𝓃-1,𝓀-1])+pBA[2𝓃,𝓀](If[𝓃==1&&𝓀==1,0,-1]+winningAmendedRecursion[𝓃-1,𝓀-1])+pBB[2𝓃,𝓀] winningAmendedRecursion[𝓃-1,𝓀]
]

Again, confirm that the recurrence equation gives the same results as direct enumeration:

Table[eExpectedBankerWinningWithAmendments[n,k]==rExpectedBankerWinningWithAmendments[n,k],{k,1,3},{n,k,k+8}]

Guess the closed form:

Table[FindSequenceFunction[Table[{n,rExpectedBankerWinningWithAmendments[n,k]},{n,Quotient[k+1,2],Quotient[k+1,2]+12}],𝓃]//Simplify,{k,1,10}]

FindSequenceFunction[%,𝓀]//FullSimplify

Check if the formula holds for higher values of parameters:

{((𝓀 (1+3 𝓀 (-1+𝓃)+𝓃))/(6 𝓃 (-1+2 𝓃))),rExpectedBankerWinningWithAmendments[𝓃,𝓀]}/.{𝓃->26,𝓀->12}

In the case of a standard 36-card pack, with type A cards being 12 face cards, the expected banker’s profit in amended and non-amended games are:

{((𝓀 (1+3 𝓀 (-1+𝓃)+𝓃))/(6 𝓃 (-1+2 𝓃))),(((-1+𝓀) 𝓀)/(2 (-1+2 𝓃)))}/.{𝓃->18,𝓀->12}//N

Problem 22

Statement

Consider a game underlaid by binary outcomes 0 or 1, with probability of 1 being p and probability of 0 being 1-p.

Titius buys single throws of a die by paying single coins to Caius. In the case of 0, he receives m coins back from Caius; otherwise, he receives nothing. In the event that Titius receives nothing n times in a row, Caius agrees to return all of his n coins. What are the lots of Titius and Caius?

Solution

n turns

Suppose the game is played n turns. Let p be the probability that Titius looses his coin in a turn:

CaiusGamePayout==Expectation[(∑_(k=1)^n)(1-m (Subscript[x, k]))-n Boole[(∑_k^n)(Subscript[x, k])==0],Table[(Subscript[x, k]),{k,n}]\[Distributed]ProductDistribution[{BernoulliDistribution[1-p],n}]] ==
Expectation[n - m tot-n Boole[tot==0],tot\[Distributed]BinomialDistribution[n,1-p]]

FullSimplify[Expectation[n - m tot-n Boole[tot==0],tot\[Distributed]BinomialDistribution[n,1-p]]==n(1-(p^n)-m(1-p)),n>1]

Code to simulate the game:

cfSimulate=Compile[{{dvec,_Integer,1},{n,_Integer},{m,_Integer}},
Module[{cv=0,p=1,k=0,res=Table[0,{Length[dvec]}]},
Do[(* Cauis unconditionally receives a coin *)
cv++;
If[r==1,
k++;If[k==n,(* Caius returns all n coins *)k=0;cv-=n];
,
(* Caius pays m coins *)
cv-=m;k=0
];
res[[p++]]=cv;
,{r,dvec}];
res
],RuntimeAttributes->{Listable}];

Find the probability for the n-turns game to be fair and perform the simulation:

With[{n=11,m=5},p/.NSolve[(1-(p^n)-m(1-p))==0&&0<p<1,p]]//Rationalize[#,1/1000]&

Block[{mvec=0},
mvec+=Mean[cfSimulate[RandomVariate[BernoulliDistribution[(14/17)],{10^6,11}],11,5]];
ListPlot[mvec,PlotLabel->"Caius' expected payout for each turn",Filling->Axis]]

Playing longer

As they would continue to play further, Caius would actually start losing money:

Block[{mvec=0},
mvec+=Mean[cfSimulate[RandomVariate[BernoulliDistribution[(14/17)],{10^6,33}],11,5]];
ListPlot[mvec,PlotLabel->"Caius' expected payout for each turn",Filling->Axis]]

The game can modeled as a Markov chain. States are labeled as state["loosing stretch length before the start of the game", "outcome of the game"], where the outcome of the game is 1 if Caius does not have to pay m coins to Titius:

Clear[outEdges];
outEdges[s0:state[x0_Integer,u0_],n_Integer]:={DirectedEdge[s0,state[Mod[x0+1,n],1]],DirectedEdge[s0,state[0,0]]}

Clear[pr];
pr[DirectedEdge[_,state[_,u_]],p_]:=If[u==0,1-p,p]

Clear[CaiusPayout];
CaiusPayout[state[x_,u_],n_,m_]:=If[u==0,-m+1,If[x==0,-n+1,1]]

Clear[gameMarkovParameters];
gameMarkovParameters[n_Integer/;n>1,m_,p_]:=Module[{vertexList,edgeList,gr,sm,p0,payoutVec},
(* set of all possible states *)
vertexList=Join[{state[0,0],state[0,1]},Table[state[x,1],{x,1,n-1}]];
(* set of all possible transitions between states *)
edgeList=Flatten[Table[outEdges[s,n],{s,vertexList}]];

(* game graph with Probability property for each transition *)
gr=Graph[vertexList,edgeList,Properties->Table[e->{Probability->pr[e,p]},{e,edgeList}]];

(* stochastic matrix *)
sm=WeightedAdjacencyMatrix[gr,EdgeWeight->Probability];
(* state probability vector after the first game *)
p0=SparseArray[{VertexIndex[gr,state[1,1]]->p,VertexIndex[gr,state[0,0]]->1-p},Length[vertexList]];
(* amount received/paid by Caius for each outcome *)
payoutVec=Table[CaiusPayout[s,n,m],{s,vertexList}];

{p0,sm,payoutVec}
]

meanTotalCaiusPayout[p0_,sm_,pout_,turns_]:=Module[{p=p0,res},
res=p0.pout;
Do[p=Together[p.sm];res+=p.pout,{turns-1}];
Together[res]
]

Confirm that the payout after n turns equals n(1-(p^n)-m(1-p)):

Table[
{p0,sm,payoutVec}=gameMarkovParameters[n,m,p];(-meanTotalCaiusPayout[p0,sm,payoutVec,n]+n(1-m(1-p)) - (p^n)n)//Simplify,{n,2,20}]

Choose the probability to make the n-turns game fair:

With[{n=10,m=3},Solve[n(1-m(1-p)) - (p^n)n==0&&0<p<1,p,Reals]]//ToRadicals

Simulate:

simulatedPayouts=Block[{mvec=0,np=N[Root[-2+#1+((#1)^2)+((#1)^3)+((#1)^4)+((#1)^5)+((#1)^6)+((#1)^7)+((#1)^8)+((#1)^9)&,1],20],reps=10^3,batch=10^5},
Do[mvec+=Total[cfSimulate[RandomVariate[BernoulliDistribution[np],{batch,10}],10,3]],{reps}];
N[Divide[mvec,batch reps]]]

exactPayouts=With[{n=10,m=3,p=N[Root[-2+#1+((#1)^2)+((#1)^3)+((#1)^4)+((#1)^5)+((#1)^6)+((#1)^7)+((#1)^8)+((#1)^9)&,1],20]},
{p0,sm,payoutVec}=gameMarkovParameters[n,m,p];Table[meanTotalCaiusPayout[p0,sm,payoutVec,k],{k,1,n}]]//N

Confirm that the expected payout is close to that observed in the experiment:

ChessboardDistance[simulatedPayouts,exactPayouts]

Compare the payout graph with the game’s initial state and the payout graph in the stationary distribution game:

Block[{n=10,m=3,p=(31/46)},
{p0,sm,payoutVec}=gameMarkovParameters[n,m,p];
pinf=PDF[StationaryDistribution[DiscreteMarkovProcess[p0,sm]],Range[Length[p0]]];
DiscretePlot[{meanTotalCaiusPayout[p0,sm,payoutVec,t],meanTotalCaiusPayout[pinf,sm,payoutVec,t]},{t,30},PlotLabel->"Caius' expected payout as a function of turns played",PlotLegends->{"Starting the game","Steady state"}]]

Caius’ expected payout in n turns in a long run

The following code builds the graph of the game, which also contains associated properties, such as stationary distribution and the payout vector:

Clear[edgeFunc];
edgeFunc[pnts_,DirectedEdge[state[x_Integer?Positive,1],state[0,0]]]:={Arrowheads[{{Medium,0.3}}],Arrow[BSplineCurve[{{x,0},{x,1/2},{x/2,1},{0,1}}]]}
edgeFunc[pnts_,DirectedEdge[state[x_Integer?Positive,1],state[0,1]]]:={Arrowheads[{{Medium,0.5}}],Arrow[BSplineCurve[{{x,0},{x/2,-1},{0,0}}]]}
edgeFunc[pnts_,DirectedEdge[state[0,0],state[0,0]]]:={Arrowheads[{{Small,0.5}}],Arrow[(pnts-ConstantArray[{0,1},Length[pnts]])/2+ConstantArray[{0,1},Length[pnts]]]}
edgeFunc[pnts_,_]:={Arrowheads[{{Medium,0.5}}],Arrow[pnts]}

Clear[gameMarkovParameters2];
gameMarkovParameters2[n_Integer/;n>1,m_,p_]:=Module[{vertexList,edgeList,gr,sm,p0,payoutVec,pinf},
(* set of all possible states *)
vertexList=DeleteCases[Flatten[Table[state[x,u],{x,0,n-1},{u,0,1}]],state[x_?Positive,0]];
(* set of all possible transitions between states *)
edgeList=Flatten[Table[outEdges[s,n],{s,vertexList}]];

(* game graph with Probability property for each transition *)
gr=Graph[vertexList,edgeList,Properties->Table[e->{Probability->pr[e,p]},{e,edgeList}],
VertexCoordinates->(vertexList/.state[x0_,u_]:>{x0,1-u}),
VertexLabels->Placed["Name",Tooltip],VertexStyle->Red,EdgeShapeFunction->edgeFunc];

(* stochastic matrix *)
sm=WeightedAdjacencyMatrix[gr,EdgeWeight->Probability];
(* state probability vector after the first game *)
p0=SparseArray[{VertexIndex[gr,state[1,1]]->p,VertexIndex[gr,state[0,0]]->1-p},Length[vertexList]];
(* amount received/paid by Caius for each outcome *)
payoutVec=Table[CaiusPayout[s,n,m],{s,vertexList}];
pinf=PDF[StationaryDistribution[DiscreteMarkovProcess[p0,sm]],Range[Length[p0]]];

SetProperty[gr,Properties->"GraphProperties"->{"StationaryProbabilities"->pinf,"InitialProbabilities"->p0,
"PayoutVector"->payoutVec}]
]

Block[{n=7,m=4,p=1/5},
gr=gameMarkovParameters2[n,m,p]]

Find the stationary distribution:

VertexList[gr]

(Normal[PropertyValue[gr,#]]&/@{"StationaryProbabilities","PayoutVector"})//Transpose

As often done by Bernoulli, we guess the functional dependence of the stationary vector components by evaluating it for different values of p and n:

With[{n=7,m=4,p=1/5},{Join[{1-p,((1-p )/(1-(p^n)))(p^n)},((1-p)/(1-(p^n)))Table[(p^k),{k,1,n-1}]],PadRight[{-m+1,-n+1},n+1,{1}]}//Transpose]

It is now straightforward to find the average-per-turn payout in the stationary case:

stationaryPayout=Collect[(1-p)(1-m)+(1-n)(p^n)((1-p)/(1-(p^n)))+((1-p)/(1-(p^n)))Sum[(p^k),{k,n-1}],m|n,FullSimplify]

Check for explicit values:

Block[{n=7,m=3,p=1/3,p0,sm,payoutVec,pinf},
{p0,sm,payoutVec}=gameMarkovParameters[n,m,p];
pinf=PDF[StationaryDistribution[DiscreteMarkovProcess[p0,sm]],Range[n+1]];
{meanTotalCaiusPayout[pinf,sm,payoutVec,1],(1-m (1-p)-((n (1-p) (p^n))/(1-(p^n))))}
]

The long-term game is fair if this payout vanishes:

Solve[1+m (-1+p)-((n (-1+p) (p^n))/(-1+(p^n)))==0,m]//FullSimplify

Block[{n=5,p=8/9,p0,sm,payoutVec},
{p0,sm,payoutVec}=gameMarkovParameters[n,(1/(1-p))-n(((p^n)/(1-(p^n)))),p];
DiscretePlot[meanTotalCaiusPayout[p0,sm,payoutVec,t],{t,60},PlotLabel->"Caius' expected payout as a function of turns played",PlotRange->{0,3}]]

By further experimentation, one can determine the closed form for the expected payout by Caius after a multiple of n turns:

Block[{n=7,p0,sm,payoutVec,pinf},
{p0,sm,payoutVec}=gameMarkovParameters[n,m,p];
Table[-meanTotalCaiusPayout[p0,sm,payoutVec,𝓀 n]+𝓀 n (1-m)(1-p)+ n p Sum[(1-(p^(r n-1))),{r,𝓀}]- (n^2)(1-p)(p^n)Sum[(p^((r-2) n))(𝓀+1-r),{r,2,𝓀}],{𝓀,1,10}]//Factor
]

Evaluate these sums:

Block[{n=11,p0,sm,payoutVec,pinf},
{p0,sm,payoutVec}=gameMarkovParameters[n,m,p];
Table[-meanTotalCaiusPayout[p0,sm,payoutVec,𝓀 n]+n(n((1-p)/(1-(p^n)))-1)((1-(p^(n 𝓀)))/(1-(p^n)))(p^n)+(1-m (1-p)-n((1-p)/(1-(p^n)))(p^n)) (n 𝓀),{𝓀,1,10}]//Simplify
]

Thus, asymptotically (large 𝓀), the total expected profit of Caius in this game equals (n((1-p)/(1-(p^n)))-1)((p^n)/(1-(p^n))) when the long-term chances each turn are equal:

Block[{n=15,p=9/10,p0,sm,payoutVec},
{p0,sm,payoutVec}=gameMarkovParameters[n,(1/(1-p))-n(((p^n)/(1-(p^n)))),p];
DiscretePlot[{meanTotalCaiusPayout[p0,sm,payoutVec,t],n(n((1-p)/(1-(p^n)))-1)((p^n)/(1-(p^n)))},{t,60},PlotLabel->"Caius' expected payout as a function of turns played",PlotRange->Full]]

Problem 23

Statement

On the game of blind dice:

A blind die has five empty sides and one side with a score. The non-empty sides of six blind dice are marked 1 through 6.

A gambler pays a coin to the dealer to roll the six blind dice and receives the payout based on the total score, according to the table. What are the chances of the gambler against the dealer?

winningsList=AssociationThread[Range[0,21],Join[{0},ConstantArray[1,8],ConstantArray[2,5],ConstantArray[3,3],{4,5,12,45,90}]]

Solution

scoreDist=TransformedDistribution[Range[6].Array[d,6],Array[d,6]\[Distributed]ProductDistribution[{BernoulliDistribution[1/6],6}]];

Table[PDF[scoreDist,k],{k,0,(∑_(n=1)^6)n}]

These probabilities can be determined more easily by using a probability-generating function:

probs=CoefficientList[Expectation[z^𝓈,𝓈\[Distributed]scoreDist],z]

The gambler’s profit can be easily found:

gamlersExpectedProfit=(probs.Values[winningsList])-1

N[%]

Problem 24

Statement

Again assuming the situation in the previous problem, if the dealer agrees to return to the gambler his five coins if no points fall to him on five throws in a row, what will be the lot of each?

Solution

Assuming that the game is played exactly five times:

gamblersExpectedProfit=With[{n=5,m=((probs.Values[winningsList])/(1-First[probs])),p=First[probs]},
-n(1-(p^n)-m(1-p))]

N[gamblersExpectedProfit]

Average per turn:

%/5

In the long run, the gambler’s expected profit per turn will asymptotically approach (see problem 22):

gamblersExpectedProfitPerTurnAsymptotically=With[{n=5,m=((probs.Values[winningsList])/(1-First[probs])),p=First[probs]},-(1-m (1-p)-n((1-p)/(1-(p^n)))(p^n))]

N[%]

Utilities

ToProportions[p_Association]:=ToProportions[Values[p]]

ToProportions[pvec:{probs__}]:=Apply[Proportion, pvec/GCD[probs]]