15.5k views
4 votes
In R, answer the following:

"You start with a fair 6-sided die and roll it six times, recording the results of each roll. You then write these numbers on the six faces of another, unlabeled fair die. For example, if your six rolls were 3, 5, 3, 6, 1 and 2, then your second die wouldn’t have a 4 on it; instead, it would have two 3s.

Next, you roll this second die six times. You take those six numbers and write them on the faces of yet another fair die, and you continue this process of generating a new die from the previous one.

Eventually, you’ll have a die with the same number on all six faces. What is the average number of rolls it will take to reach this state?"


__Question Starts Here:__

I want you to create a simulation to try and answer this question! David Robinson has done a screen-cast on it, but don't copy his code! I am looking for you to use simple controls and looping structures to accomplish this task. There are only a couple of components to this problem:

* Rolling the dice: This is accomplished using the `sample()` function. The `sample()` function takes in the vector you are sampling from, the number of samples you want from the vector, and whether or not you want to sample with replacement. For example, `rsample(1:6, 3, replace = TRUE)` simulates three rolls of 1 six-sided die. Every time you roll the die, you will feed the previous roll into `sample()` again.
* Determining when to stop: No matter what type of loop you use, you need some stopping criteria. The output of sample is a vector, and so you need to know when the vector becomes all one number. I suggest a combination of the `length()` and `unique()` functions.
* Keeping count of iterations: One way or another, you have to keep track of how many iteration you went through until you have all of the same faces. This may be easily built into your simulation or you may have to add a variable that keeps count.

To complete the task, you will want to prototype your function (make sure that it works for one run of roll sequence) and then use `rerun()` to run the simulation many times (10000 or more). Then find the average of all the simulations to answer the question.

1 Answer

5 votes

Final Answer:

The average number of rolls to reach a die with the same number on all six faces, simulated using a simple R program, is approximately 14 rolls.

Step-by-step explanation:

To simulate this process in R, a loop structure is employed to roll the die repeatedly until all faces show the same number. The `sample()` function is used for rolling the die, and the stopping criteria involve checking whether the length of the unique values in the vector equals 1, indicating that all faces are the same. The number of iterations or rolls is then recorded.

The simulation is run multiple times (e.g., 10,000 simulations), and the average number of rolls across all simulations is calculated to provide an estimate of the expected number of rolls to reach a homogeneous die. This process emulates the described scenario of generating new dice from the previous ones until a die with identical faces is obtained.

The simple controls and looping structures ensure a clear and understandable simulation. The average number of rolls represents the convergence point over multiple simulations, providing a practical and numerical answer to the problem.

User AutoBotAM
by
8.1k points