Life is like a bivouac filled with randomness and adventure. In this random aspect of life, we come across some ordinary, rather home-do-able events that make things fascinating and brings our minds to thoughts of action which speak louder than words. Keeping these things in mind, a throw of a die is probably one of the first experiments as we have learned in probability. The things we have learned are more theoretical than practical perspectives. To enlighten upon the practical aspect of this turn, we must bring in some verification to some generalized aspects and notions. This verification is done with the help of simulation. We know that each probabilistic problem has a journey on its own. We have tried our best to highlight most of it along with simulation and have tried to display a visualization of some engrossing features each problem consists of. The use of the Markov Chain in solving problems has been a real pleasure to make things even more interesting.
On constant thought of action, a throw of a die is a random event from a probabilistic aspect. On the hint of such randomness there are some basic yet interesting problems and extensions that can be raised as we constantly work on problems related to this. Let's answer some questions howsoever to work through.
We set the seed of our simulation codes at 20 so as to have some sort of reproducibility in our results
set.seed(20)
Seems like an easy enough problem, isn't it?
In other words we are asked to find expected no. of rolls until a 6 appear.
Then probability that
Thus on an average it takes 6 throws of a die before a 6 appears.
We do the simulation in the following manner:
rolls<-function()
{
x<-sample(1:6,1)
i=1
while(x!=6)
{
x<-sample(1:6,1)
i=i+1
}
return(i)
}
mean(replicate(10000,rolls()))
Upon doing the simulation, we get the value as: 6.0523
. Taking the mean from 5 times the above calculation, we also do a simulation to get a better estimate:
mean(replicate(5,mean(replicate(10000,rolls()))))
This returns a value of 6.018
We have observed by using simulation that the expected value of rolling a die until a 6 turns up is almost equal to 6. This verifies the probabilistic approach we used to find an answer to this question. The more the sample, the closer will be the result of the simulation to the number 6, as we found out in our comparative simulation.
We use recurrence relation to solve this, Let
Thus, on an average 42 is no. of times needed for a dice to be rolled until 6 appears twice in a row.
We do the simulation in the following manner:
rolls<-function()
{
j=0
x<-sample(1:6,1)
i=1
if(x==6)
{
j=1
x<-sample(1:6,1)
i=i+1
if(x!=6) j=0
}
while(j!=1)
{
x<-sample(1:6,1)
i=i+1
if(x==6)
{
j=1
x<-sample(1:6,1)
i=i+1
if(x!=6) j=0
}
}
return(i)
}
mean(replicate(10000,rolls()))
Upon running this, we found the value to be: 41.5374
.Taking the mean from 5 times the above calculation, we also do a simulation to get a better estimate:
mean(replicate(5,mean(replicate(10000,rolls()))))
This returns the value: 42.32468
We have observed by using simulation that the expected value of rolling a die until a 6 turns up twice in a row is almost equal to 42. This verifies the probabilistic approach we used to find an answer to this question. The more the sample, the closer will be the result of the simulation to the number 42, as we found out in our comparative simulation.
3. On average, how many times must a 6-sided die be rolled until the sequence 65 appears (that is a 6 followed by a 5)?
In this problem, once we roll a 6 there are 3 possibilities:
- We roll a 5
- We roll a 6
- We start over again
We again use recursion, but we will have two simultaneous equations.
Let
On solving both, we have
We do the simulation in the following manner:
rolls<-function()
{
j=0
x<-sample(1:6,1)
i=1
while(x==6)
{
j=1
x<-sample(1:6,1)
i=i+1
if(x!=5) j=0
}
while(j!=1)
{
x<-sample(1:6,1)
i=i+1
while(x==6)
{
j=1
x<-sample(1:6,1)
i=i+1
if(x!=5) j=0
}
}
return(i)
}
mean(replicate(10000,rolls()))
Upon running this, we found the value to be: 35.7654
.Taking the mean from 5 times the above calculation, we also do a simulation to get a better estimate:
mean(replicate(5,mean(replicate(10000,rolls()))))
This returns the value: 36.07392
We have observed by using simulation that the expected value of rolling a die until a 6 turns up followed by a 5 is almost equal to 36. This verifies the probabilistic approach we used to find an answer to this question. The more the sample, the closer will be the result of the simulation to the number 36, as we found out in our comparative simulation.
4. On average, how many times must a 6-sided die be rolled until there are two rolls in a row that differ by 1(such as a 2 followed by a 1 or 3, or a 6 followed by a 5)? What if we roll until there are two rolls in a row that differ by no more than 1(so we stop at a repeated roll, too)?
Let
We do the simulation in the following manner:
rolls<-function()
{
x<-sample(1:6,1);y<-sample(1:6,1)
i=2
while(abs(x-y)!=1)
{
x<-y;y<-sample(1:6,1)
i=i+1
}
return(i)
}
mean(replicate(10000,rolls()))
Upon running this, we found the value to be: 4.702
. Taking the mean from 5 times the above calculation, we also do a simulation to get a better estimate:
mean(replicate(5,mean(replicate(10000,rolls()))))
This returns the value: 4.69556
We have observed by using simulation that the expected value of rolling a die until there are two rolls in a row that differ by 1 is almost equal to 4.6862. This verifies the probabilistic approach we used to find an answer to this question. The more the sample, the closer will be the result of the simulation to the number 36, as we found out in our comparative simulation.
If we stop when we have a repeated roll too, a similar situation arises.
Defining
Solving, we get,
We do the simulation in the following manner:
rolls<-function()
{
x<-sample(1:6,1);y<-sample(1:6,1)
i=2
while(abs(x-y)>1)
{
x<-y;y<-sample(1:6,1)
i=i+1
}
return(i)
}
mean(replicate(10000,rolls()))
Upon running this, we found the value to be: 3.247
. Taking the mean from 5 times the above calculation, we also do a simulation to get a better estimate:
mean(replicate(5,mean(replicate(10000,rolls()))))
This returns the value: 3.29216
We have observed by using simulation that the expected value of rolling a die until there are two rolls in a row that differ by at most 1 is almost equal to 3.278. This verifies the probabilistic approach we used to find an answer to this question. The more the sample, the closer will be the result of the simulation to the number 3.278, as we found out in our comparative simulation.
Corollary: The expected values of rolls until there are two rolls in a row that differ by 1 is greater than the expected number of rolls until there are two rolls in a row that differ by no more than 1
Let
Hence the probability of having 6 faces appear in
We do the simulation in the following manner:
rolls<-function(n)
{
x<-sample(1:6,n,replace=T)
if(length(unique(x))==6) return(1)
else return(0)
}
mean_vec<-NULL
for(i in 1:100)
{
x<-replicate(10000,rolls(i))
mean_vec<-c(mean_vec,mean(x))
}
Then we generate a plot using:
plot(1:100,mean_vec,type='l',
xlab='No. of rolls',
ylab='Probability',
main='Probability that all the faces have appeared')
abline(v=min(which(mean_vec==1)))
The plot came out as follows:
We find that on an average after 60 rolls of a die, all the faces of a die have appeared at least once, with probability 1. This has been verified with the help of a simulation.
6. We roll a 6-sided die $n$ times. What is the probability that all faces have appeared in order, in some six consecutive rolls (i.e., what is the probability that the sub-sequence 123456 appears among the rolls)?
This problem. has a nice way to solve using Markov chains (Stochastic
Process). We define a 0 state as the state we start in and the state
we are in if the current value was not preceded by smaller value in
order (if the current roll is a 2 , but previous roll was not a 1),
and then six states corresponding to having a current \textquotedbl streak\textquotedbl{}
of
Then, the probability
We do the simulation in the following manner:
rolls<-function(n)
{
j=0
x<-sample(1:6,n,replace=T)
y<-which(x==1)
for(i in y)
{
if(n-i<5) break
else if((x[i+1]==2)&&(x[i+2]==3)&&(x[i+3]==4)&&(x[i+4]==5)&&(x[i+5]==6))
{
j=1
break
}
}
return(j)
}
mean_vec<-NULL
for(i in 1:100)
{
x<-replicate(10000,rolls(i))
mean_vec<-c(mean_vec,mean(x))
}
Then once again, we generate a plot:
plot(1:100,mean_vec,
type='l',
xlab='No. of rolls',
ylab='Probability',
main='Probability that the sequence 123456 have appeared')
The plot came out as follows:
Further, upon increasing the number of rolls to 300000, we get the result to be: 0.9988
We find an increasing trend in the probability of getting a sub-sequence as 123456 as the number of rolls is increased. We verified this using simulation. We observed that after 300000 rolls, we can say that the sub-sequence 123456 will appear at least once almost with probability 1.
7. Person A rolls $n$ dice and person B rolls $m$ dice. What is the probability that they have a common face showing (e.g., person A rolled a 2 and person B also rolled a 2, among all their dice)?
We will assume 6-sided die. Let
Now suppose
Let
Similarly,
and so,
We do the simulation in the following manner:
rolls<-function(n,m)
{
a<-sample(1:6,n,replace=T);b<-sample(1:6,m,replace=T)
return(any(unique(a)%in%unique(b)))
}
mean_mat<-matrix(,nrow=12,ncol=12)
for(i in 1:12)
{
for(j in 1:12)
{
x<-replicate(10000,rolls(i,j))
mean_mat[i,j]<-mean(x)
}
}
Finally, we draw a 3d perspective plot using:
persp(x<-1:12,y<-1:12,
mean_mat,
theta=30,phi=30,
xlab='Person A rolls',
ylab='Person B rolls',
zlab='Probability of getting a common face',
main='Probability of a common face showing',
col='#3d995a')
The plot came out as follows:
We conclude, by simulation, that if
8. On average, how many times must a pair of 6-sided dice be rolled until all sides appear at least once?
We use Markov Chains to solve this problem. We view this game as being always in one of the no. of states with a fixed probability of moving from one state to each other in one roll of dice. we define our states by the number of sides we have seen appear so far. thus we start in state 0, and wish to end up in state 6 reaching some, or all states from 1, 2, 3, 4, 5 along the way. The question states, starting in state 0, what is the expected number of rolls until we reach a state 6? We represent row 1 as state 0, row 2 as state 1 and so on. We get the following transition probability matrix:
Now,
We have the principal matrix as:
Summing up the first row, we find the expected number of rolls until
all the 6 sides have appeared
We do the simulation in the following manner:
rolls<-function()
{
a<-sample(1:6,2);i<-1
while(length(unique(a))!=6)
{
a<-c(a,sample(1:6,2,replace=T))
i=i+1
}
return(i)
}
x<-replicate(10000,rolls())
mean(x)
This returns the value as: 7.5101
We the find the maximum number of rolls needed by max(x)
and that returns the value as: 27
.
Further, the probability that the required number of rolls is more than 24, given by mean(x>24)
is: 7e-04
We have observed by using simulation that the expected value of rolling
a pair of die until all the sides appear at least once is 8. This
verifies the Markov Chain approach we've used to find an answer to
this question. Also, we find that there is less than
9. Suppose we can roll a 6-sided die up to $n$ times. At any point we can stop, and that roll becomes our "score". Our goal is to get the highest possible score, on average. How should we decide when to stop?
If
We can check the validity of our formula. For a regular, fair die,
- For
$n=1$ ,$f\left(1\right)=\frac{7}{2}=3.5$ . - For
$n=2$ ,$f\left(2\right)=\frac{17}{4}=4.25$ - For
$n=3$ ,$f\left(3\right)=\frac{28}{6}=4.667$ and so on...
We do the simulation in the following manner:
rolls<-function(n)
{
x<-sample(1:6,n,replace=T)
return(max(x))
}
mean_vec<-NULL
for(i in 1:15)
{
x<-replicate(10000,rolls(i))
mean_vec<-c(mean_vec,mean(x))
}
Then we plot the results using:
plot(1:15,mean_vec,type='l',
xlab='No. of throws',
ylab='Average score',
main='Maximum average score in n throws of a dice')
The plot came out as follows:
We draw the following conclusion regarding the highest possible score on an average:
- If
$n=1$ , we choose our score as 3 - If
$2\leq n<4$ , we choose our score as 4 - If
$n\geq4$ , we choose our score as 5
We do this, using the help of simulation which further verified our mathematical treatment of the problem. We also note that, after about 50 rolls, the highest possible score converges to 6 with probability 1.
10. Suppose we roll a fair dice 10 times. What is the probability that the sequence of rolls is non-decreasing?
The total no. of possible roll sequences if
We take a very crude method of counting these possibilities. First,
we count for
A short counting shows that the number of such outcomes, in this case
is
There are
We observe a pattern:
- For
$n=1$ , the number of our favourable cases is$6$ . - For
$n=2$ , the number of our favourable cases is the sum of the first$6$ natural numbers:$21$ . - For
$n=3$ , the number of our favourable cases is the sum of the sum of the first$i$ natural numbers,$i=1\left(1\right)6$ :$56$ - For
$n=4$ , the number of our favourable cases is the sum of the sum of the first$i$ natural numbers,$i=1\left(1\right)j,j=1\left(1\right)6$ :$126$ and so on...
For
We do the simulation in the following manner:
rolls<-function(n)
{
x<-sample(1:6,n,replace=T)
return(all(x==sort(x)))
}
n<-10
x<-replicate(1000000,rolls(n))
mean(x)
This returns a value of: 5.1e-05
Note: We note that, as
mean_vec<-NULL
for(i in 1:20)
{
x<-replicate(100000,rolls(i))
mean_vec<-c(mean_vec,mean(x))
}
plot(1:20,mean_vec,type='l',
xlab='No. of throws(n)',
ylab='Probability of a nondecreasing sequence',
main='Probability of a non-decreasing sequence in n throws of a dice')
The plot came out as follows:
We verified that the probability of rolling such a sequence is almost
- A First Course in Probability by Sheldon M. Ross
- An Introduction to Probability Theory and Its Applications by William Feller
- An Introduction to Probability and Statistics by Vijay K. Rohatgi and A.K. Md. Ehsanes Saleh