Mathematics Capstone

21
Mathematics, Probability, and Computers Brooks Davis April 25, 2014

Transcript of Mathematics Capstone

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 121

Mathematics Probability and Computers

Brooks Davis

April 25 2014

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 221

1 Introduction

Probability questions are often solved using complicated theoretical arguments Suppose

we use probability theory to determine that the probability of an event A occurring is 025

(this is denoted by P r(A) = 025) One interpretation of P r(A) = 025 is that if we conduct

the experiment 1000 times then we would expect to see the event A occur 025 lowast 1000 = 250

times We now suppose that we do not know P r(A) but have the ability to conduct the

experiment a large number of times We could then treat the proportion of times that we

observe A occurring as an approximation to P r(A)

We illustrate the thought process in the previous paragraph on the toy example of rolling

one die Let A be the event that you roll a six Probability theory tells us that P r(A) = 16

because there are six faces on the die and we assume that each face has an equal probability of

being the top face when the die is rolled If we wanted to empirically verify that P r(A) = 16

we could do the following experiment We could roll a die n times (n should be large) and

if the die landed on six i times then we would expect in to be approximately 16

Even in our toy example one would not want to actually conduct the experiment a

large number of times However computers are well suited to performing large numbers of

computations quickly so provided that one can translate the experiment into a computer

algorithm one could have a computer repeatedly conduct the experiment a large number of

times In the absence of a theoretically determined probability one could use the empirically

determined probability as a substitute for the theoretically determined probability If one

knew the theoretically determine probability beforehand then one could use the empirically

determined probability to verify the theoretically determined probability

In this paper we have selected four problems from probability and checked the theoreti-

cally determined probabilities against the empirical probabilities determined by simulation

1

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 321

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 421

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 521

Proof Summing on both sides of equation (23) yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

r ja1

ai+k minus a0 =i+k

minus1sum

j=0

r ja1

1 minus a0 = a1

9830801 minus ri+k

1 minus r

983081

a1 = 1 minus r

1 minus ri+k

Theorem 22 For every j isin 0 1 i + k a j = 1minusrj

1minusri+k

Proof We proceed by induction When j = 0 we have a0 = 0 = 1minusr0

1minusri+k Suppose for some

j isin 0 1 i + k minus 1 we have a j = 1minusrj

1minusri+k Then using the result of proposition 21 and

equation (23) we have

a j+1 = r ja1 + a j

= r j983080

1 minus r

1 minus ri+k

983081+

1 minus r j

1 minus ri+k

= r j minus r j+1 + 1 minus r j

1 minus ri+k

= 1 minus r j+1

1 minus ri+k

Proposition 22 If p = 12 then a1 = 1i+k

4

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 621

Proof Summing both sides of equation (23) with r = 1 yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

a1

1 minus a0 = a1(i + k)

a1 = 1

i + k

Theorem 23 For all j isin 0 1 i + k a j = j

i+k

Proof Again we prove this by induction Fix j isin 0 1 i + k

a j = j

i + k

a j+1 = a j + 1

i + k

= j

i + k +

1

i + k

= j + 1

i + k

Thus we have proved the following theorem

Theorem 24 If gambler A starts with i dollars gambler B starts with k dollars and p

is the probability that gambler A wins any given round then the probability that gambler A

wins is

( 1minusp

p )iminus1

( 1minusp

p )i+kminus1

if p = 12

ii+k

if p = 12

5

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 721

23 Computer Code

round[p i0 k0 ] = Module[x i = i0 k = k0x = Random[ ]

If[x lt pi = i + 1 k = k - 1k = k + 1i = i - 1] (If)i k] (Module)

game[p i0 k0 ] = Module[i = i0 k = k0 outWhile[ i gt 0 ampamp k gt 0i k = round[p i k]] (While)If[i == 0out = 0out = 1](If)out

] (Module)

ruin[p i0 k0 lim ] = Module[count = 0 n iFor[n = 1 n lt= lim n++i = game[p i0 k0]count = count + i](For)N[countlim 6]

](Module)

24 Explanation of Computer Code

We first wrote a routine Round The routine Round took three inputs i k and p

Gambler A begins the round with i dollars Gambler B begins the round with k dollars and

6

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 221

1 Introduction

Probability questions are often solved using complicated theoretical arguments Suppose

we use probability theory to determine that the probability of an event A occurring is 025

(this is denoted by P r(A) = 025) One interpretation of P r(A) = 025 is that if we conduct

the experiment 1000 times then we would expect to see the event A occur 025 lowast 1000 = 250

times We now suppose that we do not know P r(A) but have the ability to conduct the

experiment a large number of times We could then treat the proportion of times that we

observe A occurring as an approximation to P r(A)

We illustrate the thought process in the previous paragraph on the toy example of rolling

one die Let A be the event that you roll a six Probability theory tells us that P r(A) = 16

because there are six faces on the die and we assume that each face has an equal probability of

being the top face when the die is rolled If we wanted to empirically verify that P r(A) = 16

we could do the following experiment We could roll a die n times (n should be large) and

if the die landed on six i times then we would expect in to be approximately 16

Even in our toy example one would not want to actually conduct the experiment a

large number of times However computers are well suited to performing large numbers of

computations quickly so provided that one can translate the experiment into a computer

algorithm one could have a computer repeatedly conduct the experiment a large number of

times In the absence of a theoretically determined probability one could use the empirically

determined probability as a substitute for the theoretically determined probability If one

knew the theoretically determine probability beforehand then one could use the empirically

determined probability to verify the theoretically determined probability

In this paper we have selected four problems from probability and checked the theoreti-

cally determined probabilities against the empirical probabilities determined by simulation

1

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 321

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 421

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 521

Proof Summing on both sides of equation (23) yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

r ja1

ai+k minus a0 =i+k

minus1sum

j=0

r ja1

1 minus a0 = a1

9830801 minus ri+k

1 minus r

983081

a1 = 1 minus r

1 minus ri+k

Theorem 22 For every j isin 0 1 i + k a j = 1minusrj

1minusri+k

Proof We proceed by induction When j = 0 we have a0 = 0 = 1minusr0

1minusri+k Suppose for some

j isin 0 1 i + k minus 1 we have a j = 1minusrj

1minusri+k Then using the result of proposition 21 and

equation (23) we have

a j+1 = r ja1 + a j

= r j983080

1 minus r

1 minus ri+k

983081+

1 minus r j

1 minus ri+k

= r j minus r j+1 + 1 minus r j

1 minus ri+k

= 1 minus r j+1

1 minus ri+k

Proposition 22 If p = 12 then a1 = 1i+k

4

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 621

Proof Summing both sides of equation (23) with r = 1 yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

a1

1 minus a0 = a1(i + k)

a1 = 1

i + k

Theorem 23 For all j isin 0 1 i + k a j = j

i+k

Proof Again we prove this by induction Fix j isin 0 1 i + k

a j = j

i + k

a j+1 = a j + 1

i + k

= j

i + k +

1

i + k

= j + 1

i + k

Thus we have proved the following theorem

Theorem 24 If gambler A starts with i dollars gambler B starts with k dollars and p

is the probability that gambler A wins any given round then the probability that gambler A

wins is

( 1minusp

p )iminus1

( 1minusp

p )i+kminus1

if p = 12

ii+k

if p = 12

5

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 721

23 Computer Code

round[p i0 k0 ] = Module[x i = i0 k = k0x = Random[ ]

If[x lt pi = i + 1 k = k - 1k = k + 1i = i - 1] (If)i k] (Module)

game[p i0 k0 ] = Module[i = i0 k = k0 outWhile[ i gt 0 ampamp k gt 0i k = round[p i k]] (While)If[i == 0out = 0out = 1](If)out

] (Module)

ruin[p i0 k0 lim ] = Module[count = 0 n iFor[n = 1 n lt= lim n++i = game[p i0 k0]count = count + i](For)N[countlim 6]

](Module)

24 Explanation of Computer Code

We first wrote a routine Round The routine Round took three inputs i k and p

Gambler A begins the round with i dollars Gambler B begins the round with k dollars and

6

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 321

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 421

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 521

Proof Summing on both sides of equation (23) yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

r ja1

ai+k minus a0 =i+k

minus1sum

j=0

r ja1

1 minus a0 = a1

9830801 minus ri+k

1 minus r

983081

a1 = 1 minus r

1 minus ri+k

Theorem 22 For every j isin 0 1 i + k a j = 1minusrj

1minusri+k

Proof We proceed by induction When j = 0 we have a0 = 0 = 1minusr0

1minusri+k Suppose for some

j isin 0 1 i + k minus 1 we have a j = 1minusrj

1minusri+k Then using the result of proposition 21 and

equation (23) we have

a j+1 = r ja1 + a j

= r j983080

1 minus r

1 minus ri+k

983081+

1 minus r j

1 minus ri+k

= r j minus r j+1 + 1 minus r j

1 minus ri+k

= 1 minus r j+1

1 minus ri+k

Proposition 22 If p = 12 then a1 = 1i+k

4

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 621

Proof Summing both sides of equation (23) with r = 1 yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

a1

1 minus a0 = a1(i + k)

a1 = 1

i + k

Theorem 23 For all j isin 0 1 i + k a j = j

i+k

Proof Again we prove this by induction Fix j isin 0 1 i + k

a j = j

i + k

a j+1 = a j + 1

i + k

= j

i + k +

1

i + k

= j + 1

i + k

Thus we have proved the following theorem

Theorem 24 If gambler A starts with i dollars gambler B starts with k dollars and p

is the probability that gambler A wins any given round then the probability that gambler A

wins is

( 1minusp

p )iminus1

( 1minusp

p )i+kminus1

if p = 12

ii+k

if p = 12

5

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 721

23 Computer Code

round[p i0 k0 ] = Module[x i = i0 k = k0x = Random[ ]

If[x lt pi = i + 1 k = k - 1k = k + 1i = i - 1] (If)i k] (Module)

game[p i0 k0 ] = Module[i = i0 k = k0 outWhile[ i gt 0 ampamp k gt 0i k = round[p i k]] (While)If[i == 0out = 0out = 1](If)out

] (Module)

ruin[p i0 k0 lim ] = Module[count = 0 n iFor[n = 1 n lt= lim n++i = game[p i0 k0]count = count + i](For)N[countlim 6]

](Module)

24 Explanation of Computer Code

We first wrote a routine Round The routine Round took three inputs i k and p

Gambler A begins the round with i dollars Gambler B begins the round with k dollars and

6

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 421

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 521

Proof Summing on both sides of equation (23) yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

r ja1

ai+k minus a0 =i+k

minus1sum

j=0

r ja1

1 minus a0 = a1

9830801 minus ri+k

1 minus r

983081

a1 = 1 minus r

1 minus ri+k

Theorem 22 For every j isin 0 1 i + k a j = 1minusrj

1minusri+k

Proof We proceed by induction When j = 0 we have a0 = 0 = 1minusr0

1minusri+k Suppose for some

j isin 0 1 i + k minus 1 we have a j = 1minusrj

1minusri+k Then using the result of proposition 21 and

equation (23) we have

a j+1 = r ja1 + a j

= r j983080

1 minus r

1 minus ri+k

983081+

1 minus r j

1 minus ri+k

= r j minus r j+1 + 1 minus r j

1 minus ri+k

= 1 minus r j+1

1 minus ri+k

Proposition 22 If p = 12 then a1 = 1i+k

4

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 621

Proof Summing both sides of equation (23) with r = 1 yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

a1

1 minus a0 = a1(i + k)

a1 = 1

i + k

Theorem 23 For all j isin 0 1 i + k a j = j

i+k

Proof Again we prove this by induction Fix j isin 0 1 i + k

a j = j

i + k

a j+1 = a j + 1

i + k

= j

i + k +

1

i + k

= j + 1

i + k

Thus we have proved the following theorem

Theorem 24 If gambler A starts with i dollars gambler B starts with k dollars and p

is the probability that gambler A wins any given round then the probability that gambler A

wins is

( 1minusp

p )iminus1

( 1minusp

p )i+kminus1

if p = 12

ii+k

if p = 12

5

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 721

23 Computer Code

round[p i0 k0 ] = Module[x i = i0 k = k0x = Random[ ]

If[x lt pi = i + 1 k = k - 1k = k + 1i = i - 1] (If)i k] (Module)

game[p i0 k0 ] = Module[i = i0 k = k0 outWhile[ i gt 0 ampamp k gt 0i k = round[p i k]] (While)If[i == 0out = 0out = 1](If)out

] (Module)

ruin[p i0 k0 lim ] = Module[count = 0 n iFor[n = 1 n lt= lim n++i = game[p i0 k0]count = count + i](For)N[countlim 6]

](Module)

24 Explanation of Computer Code

We first wrote a routine Round The routine Round took three inputs i k and p

Gambler A begins the round with i dollars Gambler B begins the round with k dollars and

6

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 521

Proof Summing on both sides of equation (23) yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

r ja1

ai+k minus a0 =i+k

minus1sum

j=0

r ja1

1 minus a0 = a1

9830801 minus ri+k

1 minus r

983081

a1 = 1 minus r

1 minus ri+k

Theorem 22 For every j isin 0 1 i + k a j = 1minusrj

1minusri+k

Proof We proceed by induction When j = 0 we have a0 = 0 = 1minusr0

1minusri+k Suppose for some

j isin 0 1 i + k minus 1 we have a j = 1minusrj

1minusri+k Then using the result of proposition 21 and

equation (23) we have

a j+1 = r ja1 + a j

= r j983080

1 minus r

1 minus ri+k

983081+

1 minus r j

1 minus ri+k

= r j minus r j+1 + 1 minus r j

1 minus ri+k

= 1 minus r j+1

1 minus ri+k

Proposition 22 If p = 12 then a1 = 1i+k

4

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 621

Proof Summing both sides of equation (23) with r = 1 yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

a1

1 minus a0 = a1(i + k)

a1 = 1

i + k

Theorem 23 For all j isin 0 1 i + k a j = j

i+k

Proof Again we prove this by induction Fix j isin 0 1 i + k

a j = j

i + k

a j+1 = a j + 1

i + k

= j

i + k +

1

i + k

= j + 1

i + k

Thus we have proved the following theorem

Theorem 24 If gambler A starts with i dollars gambler B starts with k dollars and p

is the probability that gambler A wins any given round then the probability that gambler A

wins is

( 1minusp

p )iminus1

( 1minusp

p )i+kminus1

if p = 12

ii+k

if p = 12

5

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 721

23 Computer Code

round[p i0 k0 ] = Module[x i = i0 k = k0x = Random[ ]

If[x lt pi = i + 1 k = k - 1k = k + 1i = i - 1] (If)i k] (Module)

game[p i0 k0 ] = Module[i = i0 k = k0 outWhile[ i gt 0 ampamp k gt 0i k = round[p i k]] (While)If[i == 0out = 0out = 1](If)out

] (Module)

ruin[p i0 k0 lim ] = Module[count = 0 n iFor[n = 1 n lt= lim n++i = game[p i0 k0]count = count + i](For)N[countlim 6]

](Module)

24 Explanation of Computer Code

We first wrote a routine Round The routine Round took three inputs i k and p

Gambler A begins the round with i dollars Gambler B begins the round with k dollars and

6

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 621

Proof Summing both sides of equation (23) with r = 1 yields

i+kminus1sum j=0

(a j+1 minus a j) =i+kminus1sum j=0

a1

1 minus a0 = a1(i + k)

a1 = 1

i + k

Theorem 23 For all j isin 0 1 i + k a j = j

i+k

Proof Again we prove this by induction Fix j isin 0 1 i + k

a j = j

i + k

a j+1 = a j + 1

i + k

= j

i + k +

1

i + k

= j + 1

i + k

Thus we have proved the following theorem

Theorem 24 If gambler A starts with i dollars gambler B starts with k dollars and p

is the probability that gambler A wins any given round then the probability that gambler A

wins is

( 1minusp

p )iminus1

( 1minusp

p )i+kminus1

if p = 12

ii+k

if p = 12

5

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 721

23 Computer Code

round[p i0 k0 ] = Module[x i = i0 k = k0x = Random[ ]

If[x lt pi = i + 1 k = k - 1k = k + 1i = i - 1] (If)i k] (Module)

game[p i0 k0 ] = Module[i = i0 k = k0 outWhile[ i gt 0 ampamp k gt 0i k = round[p i k]] (While)If[i == 0out = 0out = 1](If)out

] (Module)

ruin[p i0 k0 lim ] = Module[count = 0 n iFor[n = 1 n lt= lim n++i = game[p i0 k0]count = count + i](For)N[countlim 6]

](Module)

24 Explanation of Computer Code

We first wrote a routine Round The routine Round took three inputs i k and p

Gambler A begins the round with i dollars Gambler B begins the round with k dollars and

6

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 721

23 Computer Code

round[p i0 k0 ] = Module[x i = i0 k = k0x = Random[ ]

If[x lt pi = i + 1 k = k - 1k = k + 1i = i - 1] (If)i k] (Module)

game[p i0 k0 ] = Module[i = i0 k = k0 outWhile[ i gt 0 ampamp k gt 0i k = round[p i k]] (While)If[i == 0out = 0out = 1](If)out

] (Module)

ruin[p i0 k0 lim ] = Module[count = 0 n iFor[n = 1 n lt= lim n++i = game[p i0 k0]count = count + i](For)N[countlim 6]

](Module)

24 Explanation of Computer Code

We first wrote a routine Round The routine Round took three inputs i k and p

Gambler A begins the round with i dollars Gambler B begins the round with k dollars and

6

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 821

p is the probability that gambler A wins the round

Round selected a random number x from a uniform distribution on the interval [0 1]

If x lt p Round increased i by 1 and decreased k by 1 If x ge p Round increased k by 1

and decreased i by 1 Round returned the updated values of i and k

Next we wrote a routine Game Game took inputs i k and p Game utilized a ldquowhilerdquo

loop The body of the ldquowhilerdquo loop consisted of Game calling Round to increment i and k

The ldquowhilerdquo loop was exited when either i = 0 or k = 0 thus simulating one complete game

of Gamblerrsquos Ruin

The final routine Ruin ran Game n times and kept a tally of the games won by gambler

A The number of games won by A was divided by n to determine empirically the probability

that gambler A would win Gamblerrsquos Ruin with the given initial conditions

25 Results

We ran Ruin with parameters n = 10 000 i = 20 k = 5 and p = 04 With these pa-

rameters the theoretical probability as determined by Theorem 24 is approximately 0 1317

Table 1 shows the empirically probability computed by Ruin in ten runs

Table 1 Empirical Probabilities of Gamblerrsquos Ruin

Run Number Probability Run Number Probability

1 01313 6 01318

2 01307 7 01292

3 01352 8 01340

4 01308 9 01341

5 01333 10 01362

7

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 921

3 Full House

31 Problem

A standard deck of 52 cards consists of four different suits (Spades Hearts Clubs and

Diamonds) Each suit is then made up of 13 ranks (Ace 2 3 10 Jack Queen and

King) A hand in poker consists of five cards The hand known as a full house consists of

three of one rank and a pair of another We now consider the probability that a randomly

dealt hand of five cards is a full house

32 Formula

We will now count the number of full houses there are Suppose you are holding a full house

There are 13 different ranks for the three of a kind For each of those ranks there are four

different cards to choose three from ie there are104861643

1048617three of a kinds from each rank There

are 12 remaining ranks to have the pair in and for each of those 12 there are104861642

1048617 possible

pairs The total number of unordered hands is given by1048616525

1048617 Thus the probability of being

randomly dealt a full house is

13 lowast104861643

1048617lowast 12 lowast

104861642

10486171048616525

1048617 = 6

4165 asymp 0001441

33 Computer Code

deal = Module[card1 card2 card3 card4 card5card1 = Random[Integer 1 4] Random[Integer 1 13]

card2 = card1While[card2 == card1card2 = Random[Integer 1 4] Random[Integer 1 13]](While)card3 = card1While[card3 == card1 mdashmdash card3 == card2card3 = Random[Integer 1 4] Random[Integer 1 13]

8

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1021

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1121

34 Explanation of Computer Code

We encoded each card as an ordered pair The first entry of the ordered pair was an integer

from 1 to 4 representing the suit of the card The second entry was an integer from 1 to 13

representing the rank of the card

We first wrote a routine Deal Deal randomly dealt a first card as described in the

paragraph above We used a ldquowhilerdquo loop to keep drawing until the second card was distinct

from the first card In a similar manner the third fourth and fifth cards were repeatedly

drawn until each card did not match any of the previously drawn cards

Next we had to determine a way for the computer to tell whether or not a hand contained

a full house Typically if a human is holding a fullhouse they will arrange the matching ranks

to be adjacent However the hand the computer is holding is not arranged in any particular

order For instance the first third and fifth card may all be the same rank and the second

and fourth may be the same rank or the first and fifth card are the same rank and the

second third and fourth card are the same rank To get around this difficulty we wrote a

routine Hand The input to Hand was a list of five cards and each card was a list of two

integers Hand returned a list of 13 integers where the ith number on the list is the number

of cards of rank i in the hand

For example the hand consisting of a 5 of diamonds a 6 of clubs a 5 of hearts an Ace

of hearts and a 10 of spades would be coded as

4 5 3 6 2 5 2 1 1 10 (34)

When Hand receives the input (34) it would return the 13-vector

1 0 0 0 2 1 0 0 0 1 0 0 0

Next we observe that a hand is a full house if and only if the 13-vector returned by Hand

10

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1221

was all zero except for having exactly one 3 and one 2

Thus we wrote a routine Fullhouse Fullhouse received the output of Hand and returned

a 1 if and only if the 13-vector met the requirement to represent a full house as stated in the

previous paragraph

The final routine Winning had a single input n Winning was a loop which ran n times It

would deal a hand with Deal pass the hand to Hand and then pass this output to Fullhouse

Finally Winning would increment a counter by the output of Fullhouse Then Winning

returned an empirically determined probability that a randomly dealt hand of five cards

would be a full house

35 Results

Table 2 shows the output of Winning with n = 100 000 The theoretical probability is

0001441

Table 2 Empirical Probability of being Dealt a Full House

Run Number Probability Run Number Probability

1 000148 6 000138

2 000134 7 000161

3 000154 8 000134

4 000144 9 000137

5 000159 10 000146

4 Craps

41 Problem

Craps is a game where one player rolls two fair dice The two dice are then added together and

their sum is observed The player immediately wins if the sum is a 7 or 11 He immediately

11

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1321

loses if the sum is a 2 3 or 12 If the sum of the roll is a 4 5 6 8 9 or 10 the player must

continue to roll until either a 7 or the first sum is rolled again If the player matches the

sum of his first roll before rolling a 7 he wins If the player rolls a 7 before he rolls his first

sum he loses What is the probability that a player will win a game of craps

42 Formula

Let W be the event that a player wins a game of craps Since the way the game is played

is heavily dependent on the first roll we will condition on the outcome of the first roll For

2 le i le 12 let F i be the event that you roll a sum of i on the first roll Then by the Law of

Total Probabilities we have

P (W ) =12sumi=2

P (W |F i)P (F i) (45)

We will carefully examine the case where the first roll is a sum of 4 and then the pattern

will be clear Let R4 be the event of rolling a sum of 4 on a single roll The probability of

eventually rolling a 4 before rolling a 7 given that the first roll is a 4 is given by P (R4)P (R4)+P (R7)

and therefore we have

P (W |F 4) = P (R4)

P (R4) + P (R7) =

336

336 + 636 =

3

9

Computing in a similar manner we have

P (W |R2) = 0 P (W |R3) = 0 P (W |R4) = 39

P (W |R5) = 410

P (W |R6) = 511 P (W |R7) = 1 P (W |R8) = 5

11 P (W |R9) = 410

P (W |R10) = 39 P (W |R11) = 1 P (W |R12) = 0

12

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1421

Now we compute each term in equation (45)

P (W |R2)P (R2) = 0 middot 136 = 0 P (W |R3)P (R3) = 0 middot 2

36 = 0

P (W |R4)P (R

4) = 3

9 middot 3

36 = 1

36 P (W |R

5)P (R

5) = 4

10 middot 4

36 = 2

45

P (W |R6)P (R6) = 511

middot 536

= 25396

P (W |R7)P (R7) = 1 middot 636

= 16

P (W |R8)P (R8) = 511

middot 536

= 25396 P (W |R9)P (R9) = 4

10 middot 4

36 = 2

45

P (W |R10)P (R10) = 39

middot 336 = 1

36 P (W |R11)P (R11) = 1 middot 236 = 1

18

P (W |R12)P (R12) = 0 middot 136 = 0

Thus the probability of winning craps is given by summing the previous table

P (W ) =12sumi=2

P (W |F i)P (F i) = 244

495 = 04929

43 Computer Code

roll = Module[x yx = Random[Integer 1 6]y = Random[Integer 1 6]x + y](Module)

game = Module[firstroll currentrollfirstroll = rollSwitch[firstroll7 out = 1Goto[end]11 out = 1Goto[end]2 out = 0Goto[end]3 out = 0Goto[end]12 out = 0

13

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1521

Goto[end]

currentroll = -1While[currentroll = 7 ampamp currentroll = firstroll

currentroll = roll](While)](Switch)If[currentroll == firstrollout = 1 out = 0](If)Label[end]out](Module)

craps[n ] = Module[count = 0Do[count = count + gamen](Do)N[countn 6]](Module)

44 Explanation of Computer Code

The first routine we wrote was Roll The output for Roll was an integer between 2 and 12

inclusively We could not have Mathematica randomly pick an integer between 2 and 12

because that would not represent the probability of rolling any given sum with two dice So

we uniformly randomly chose two integers between 1 and 6 inclusively and summed them

to mimic the rolling of the dice

The next routine we wrote was Game Game provided a simulation of one complete

game of craps Thus Game required no inputs and returned a 1 if you won or a 0 if you lost

We first initialized a variable Firstroll with Roll We placed a ldquoLabelrdquo named end at the very

end of Game In order to decide the subsequent steps following the first roll we implemented

a ldquoSwitchrdquo in Mathematica Basically a ldquoSwitchrdquo is a multi-ary ldquoIf then elserdquo statement

14

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1621

The ldquoSwitchrdquo was implemented on Firstroll If the value of Firstroll was a 7 or 11 we set out

the output of Game equal to one and used a ldquoGotordquo statement to jump to the ldquoLabelrdquo end

and thus terminate Game If the value for Firstroll was a 2 3 or 12 we set out equal to zero

and jumped to end Mathematica executes the lines after the underscore if Firstroll was none

of the explicitly listed values for the ldquoSwitchrdquo For all other values of Firstroll we continued

the game with a ldquoWhilerdquo loop We initialized Currentroll to minus1 to make sure the ldquoWhilerdquo

loop was run at least once The ldquoWhilerdquo loop continued to update Currentroll by Roll until

Currentroll was either a 7 or equal to Firstroll Finally we set out equal to 1 if Currentroll was

equal to Firstroll or set out equal to 0 otherwise

The last routine we wrote was Craps Craps takes an input n and runs Game n times

We incremented a counter by the output of Game The final output is the counter divided

by the input n which gives us an empirically determined probability for winning craps

45 Results

The exact probability of winning a game of craps is 04929 Table 3 shows the empirical

probabilities of winning a game of craps

n = 1 000 000

Table 3 Empirical Probability of Winning Craps

Run Number Probability Run Number Probability

1 0493118 6 0493918

2 0493154 7 0493146

3 0493428 8 0492831

4 0492829 9 0493869

5 0492872 10 0492891

15

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1721

5 Birthday Problem

51 Problem

Suppose you meet a random father of two kids You find out that one of his kids is a boy

born on Tuesday What is the probability that his other child is a boy

A typical reaction to this problem is that one assumes that the probability is 50 based

on the assumption of independence of the genders of the children However we will see that

the probability in question is not 50

52 Formula

Assume that the probability that a child is a boy is 50 Assume that the probability

that a child is born any given day of the week is 17 The sample space for the experiment

consists of pairs of children We can represent each child as an ordered pair with the first

entry being a 0 or a 1 and the second entry being a integer from 1 to 7 For instance we

represent a boy born on Tuesday by (0 3) We represent a pair of kids by a pair of such

ordered pairs Ie a pair of children is represented by a tuple of the form

((x1 y1) (x2 y2)) (56)

where xi isin 0 1 and yi isin 1 2 7 For example if the children in a family consist of a

boy born on Tuesday and a girl born on Saturday we represent this as ((0 3) (1 7)) Let

S be the set of all such ordered pairs of ordered pairs We assume that there is a first child

and a second child in each such family Let A be the event that at least one of the childrenis a boy born on Tuesday and the other child is a boy Let B be the event that at least one

of the children is a boy born on Tuesday The probability we seek is

P r(A|B) = P (A cap B)

P (B) =

P r(A)

P r(B) =

|A||S |

|B||S | =

|A|

|B|

16

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1821

The ordered pairs in B consist of all the ordered pairs beginning with (0 3) of which

there are 14 Also B contains all the ordered pairs ending in (0 3) which there are also 14

of However we must subtract off one for the pair ((0 3) (0 3)) otherwise we would have

counted this ordered pair twice Thus |B| = 14+ 14minus 1 = 27 The ordered pairs in A consist

of all ordered pairs beginning with (0 3) and starting with a 0 in the first slot of the second

ordered pair of which there are 7 Also A consists of all ordered pairs ending with a (0 3)

and starting with a 0 in the first slot of the first ordered pair of which there are 7 Again

we have to subtract 1 to prevent the ordered pair ((0 3) (0 3)) from being counted twice

Thus |A| = 7 + 7 minus 1 = 13 So

P r(A|B) = |A||B|

= 1327

= 0481

53 Computer Code

sample = Random[Integer 0 1]Random[Integer 1 7] Random[Integer 0 1]Random[Integer 1 7]

family = Module[out kids = sample tempWhile[kids[[1]] = 0 3 ampamp kids[[2]] = 0 3kids = sample](While)If[kids[[1]] = 0 3temp = kids[[1]]kids[[1]] = kids[[2]]

kids[[2]] = temp](If)If[kids[[2]][[1]] == 0out = 1out = 0](If)

17

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 1921

out](Module)

boytuesday[n ] = Module[count = 0Do[count = count + familyn](Do)N[countn 6]](Module)

54 Explanation of Computer Code

The first routine we wrote was Sample Sample produces a random tuple of the form (56)

The next routine we wrote was Family Family used a variable Kids of the form (56) Using

a ldquoWhilerdquo loop Family repeatedly called Sample until at least one of the pairs was a boy

born on Tuesday Then if the first pair in Kids was not a boy born on Tuesday we swapped

the two pairs such that the first pair of Kids was always a boy born on Tuesday Then Family

looked at the first entry of the second ordered pair and returned a 1 if it was a boy or a 0

otherwiseThe final routine BoyTuesday had one input parameter n BoyTuesday called Family

n times and incremented a counter Count by the output of Family BoyTuesday returned

Countn The value that BoyTuesday returns is the empirically determined probability that

the other child is a boy given that one of the children is a boy born on Tuesday

55 Results

Table 4 shows the empirical probabilities of the birthday problem Notice all the probabilities

are less than 12 and therefore this empirical data alone suggests that the probability in

question is less than 12 Moreover all the entries in Table 4 are close to the theoretical

18

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2021

probability 0481 which serves as strong evidence that the theoretical probability is correct

Table 4 Empirical Probability for Birthday Problem

Run Number Probability Run Number Probability1 0481815 6 0481592

2 0482101 7 0481592

3 0481531 8 0481984

4 0480895 9 0481437

5 0481583 10 0481407

6 Conclusion

Throughout this project we both empirically determined and theoretically determined

probabilities for certain problems In the end the results from our empirically determined

probabilities were really close to the theoretical ones This demonstrates that there are

diverse ways to solve probability problems It all depends on who is trying to solve them

Some people may not be as fluent with programming so they may have to solve problems

by hand but also there may be someone that can not solve some problems by hand We

also realized that some problems may be difficult to solve using the theory but may be

relatively easy to solve via simulations and vice versa A problem such as Gamblerrsquos Ruin

was extremely difficult to solve by hand but it was simple to program given that you have

that ability Fullhouse was very simple to solve in theory but proved difficult to write a

program for There are a couple of things that I can do further with this project in the

future One is that I can look deeper into the empirically determined probabilities and

study the variance and error among the results This project used my mathematical skills

as well as my computer science skills to combine the two and show how technology can help

with math

19

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20

8102019 Mathematics Capstone

httpslidepdfcomreaderfullmathematics-capstone 2121

References

[MD] Degroot Morris H Schervish Mark J Probability and Statistics Boston MA

Pearson Education Inc 2012

20