The is a multiple-player game played with one 6-sided die. During a player\'s tu
ID: 3830559 • Letter: T
Question
The is a multiple-player game played with one 6-sided die. During a player's turn, a player repeatedly rolls the die until either they decide to stop or they roll a one. whichever comes first. If a player rolls a one. they get 0 points for that turn; otherwise, if they stop before rolling a one. their point total for that turn is the sum of all the values they rolled on that turn. The first player to get to 100 or more total points wins. How many rolls can a player take, on average, without rolling a one? What is the average number of points a player can get without roling a one? You may have an idea of what the answers should be. In this problem, you will model rolling the die using MATLAB's function and determine the results experimentally. a. Write a function named that takes no parameters. The function should simulate repeatedly rolling a 6-sided die until a one is rolled. The function returns a row vector containing the number of rolls taken before the one is rolled (i.e.. not including the roll that resulted in a one) and the total points scored before the one is rolled. For example, if the sequence of values rolled is 4, 2, 5, 4, 1 then the number of rolls is 4 and the total points scored is 15. The first line of your function should be: function [rolls, points] = rollUntilOne() In order to get full credit, your function must use a while loop. [numRolls, turnScore] = rollUntilOne(); If, for example, your function returned then after the code above executed, the variable would contain the value 4 and the value 15 would contain the value 15. If instead you had used the code, then the variable would just contain the value 4 (and the value 15 would be ignored). b. If you run your several times, you will find that you get different results each time. Suppose we consider one call to to be a single trial. Write a code fragment that runs 5000 trials and then displays the average number of rolls before rolling a one and the average number of points scored.Explanation / Answer
a) Matlab code:
function [rolls, points] = rollUnitones()
d = randperm(6,1);
rolls = [];
while(d ~= 1)
rolls = [rolls, d];
d = randperm(6,1);
end
points = sum(rolls);
end
b) Matlab code:
lengths = 0;
s = 0;
for i = 1:5000
[rolls, score] = rollUnitones();
lengths = lengths + size(rolls,2);
s = s + score;
end
Average_rolls = lengths/5000
Average_scores = s/5000
Sample Output:
Average_rolls =
4.9852
Average_scores =
19.9944
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.