Ch. 11 #17 Toss a fair die repeatedly. Let Sn denote the total of the outcomes through the nth toss. Show that there is a limiting value for the proportion of the first n values of Sn that are divisible by 7, and compute the value for this limit. Hint: The desired limit is an equilibrium probability vector for an appropriate seven state Markov chain.

# Function to simulate die tosses and compute S_n
simulate_die_tosses <- function(n) {
  die_outcomes <- sample(1:6, n, replace = TRUE)  # Simulate die tosses
  S_n <- cumsum(die_outcomes)  # Compute cumulative sum
  return(S_n)
}

# Number of tosses
n <- 10000

# Simulate die tosses
S_n_values <- simulate_die_tosses(n)

# Compute proportion divisible by 7
proportion_divisible_by_7 <- sum(S_n_values %% 7 == 0) / n

# Print the result
cat("Proportion of the first", n, "values of S_n divisible by 7:", proportion_divisible_by_7, "\n")
## Proportion of the first 10000 values of S_n divisible by 7: 0.1483