A teacher in school told us about this math problem:
- Problem 1: On average, how many times do you need to roll a dice before you see a 4 followed by a 6?
- Problem 2: On average, how many times do you need to roll a dice before you see a 6 followed by a 6?
Apparently, even though we might think that rolling any number on a dice has equal probability, the answer to Problem 1 is not the same as Problem 2!
In another post (https://stackoverflow.com/questions/69081795/simulating-dice-rolls-in-r), I learned how to write a function (using the R programming language) to simulate both of these problems:
Problem 1:
# Problem 1 (4 followed by 6):
roll_from_4_to6 <- function() {
n <- 1:6
i <- 1
previous_4 <- FALSE
while(TRUE) {
current_value = sample(n, 1)
i <- i + 1
if(previous_4 && current_value == 6) break
previous_4 <- current_value == 4
}
i
}
mean(replicate(100000, roll_from_4_to6()))
[1] 36.92289
Problem 2:
# Problem 2 (6 followed by 6):
roll_from_6_to6 <- function() {
n <- 1:6
i <- 1
previous_4 <- FALSE
while(TRUE) {
current_value = sample(n, 1)
i <- i + 1
if(previous_4 && current_value == 6) break
previous_4 <- current_value == 6
}
i
}
mean(replicate(100000, roll_from_6_to6()))
[1] 43.25653
As we can see here, the number of times needed to roll a "4 followed by a 6" is clearly different than a "6 followed by a 6". I have always tried to find a mathematical explanation for what is happening. I heard this problem can be solved using Markov Chains - but I am not sure how to set up the Transition Matrix for these problems and calculate the number of "steps" (i.e. raising the transition matrix to the power of "k") required to reach the Absorption State.
Can someone please show me how to do this specifically using Markov Chains?
Thanks!