Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB: Suppose you had five dice, where each die when rolled will give values b

ID: 3864372 • Letter: M

Question

MATLAB:

Suppose you had five dice, where each die when rolled will give values between one and six. Write a function called problem3 that continuously generates a vector representing five dice. The function should continually simulate the rolling of five dice together (represented by random values between one and six in a fiveelement vector) until a "large straight" is achieved. A "large straight" is achieved when one simultaneous roll of five dice produces values 1, 2, 3, 4, 5 or values 2, 3, 4, 5, 6. The function should print each collective roll of the five dice until a large straight is achieved. Once a large straight is achieved, the function should print "Large straight! " (note the new line character at the end). Notice that this function "prints" its output, hence this function does not have any output arguments.

This problem requires that you generate random integers using randi. Make sure you don't generate a random integer and not use it. The grader assumes that all generated values are used. Hence, for every roll (iteration), generate five one random integers between one and six.
  


To allow for the grader to generate the same sequence of random values as your function, you are required to call the rng function in your solution before you make any call to randi. The "seed" for the rng function will be passed as an input argument. Suppose the input argument is named seed, you must have the following line of code in your function. It should be written only once in your function and it is highly recommended that this is the first line in your function body.

rng(seed);

Notes: - The function should accept one input argument, namely the seed. - You are prohibited from using a for-loop. - If you are not getting the same output, try printing the random integers as you are generating them. - Note that a "large straight" can be achieved in any order of the simulated values of the dice. Since a vector is being used to store the values of rolling five dice at once, you may consider using the sort built-in function. - As stated above, the function does not have any output arguments. You will print directly to the Command Window. Since the grader will be checking the output that you print to the Command Window, your output has to be identical to the output of the solution (based on the value of the random number generator seed). Example outputs are given below. You may consider using the mat2str built-in function to print the contents of the vector. Make sure there are no additional whitespaces after printing the vector at the end of each line (i.e., print the vector and go directly to the next line). Similarly, after you print "Large straight!", make sure you include a new line after it (but again, no white spaces after it).

Below are some sample executions (if you think your output is correct and is identical to the sample executions below, but the tester still reports it as incorrect, contact the instructor):

>> problem3(915906)

[5 4 3 6 2]

Large straight!

>> problem3(830481)

[4 1 3 1 4] [1 2 4 5 3]

Large straight!

>> problem3(764095)

[4 6 5 5 2] [5 2 6 4 5] [6 5 4 6 5] [4 4 6 6 1] [1 5 6 5 6] [3 1 4 2 5]

Large straight! #a new line character present after the exclamation point

Explanation / Answer

Solution:

function [] = Problem3(seed)
rng(seed);
random_roll=zeros(1,5);
while 1
random_roll = randi(6,1,5);
disp(random_roll);
if(random_roll == [1,2,3,4,5])
break;
elseif(random_roll==[2,3,4,5,6])
break;
end
end
end

Output:

Problem3(915906)

I am getting larger output.Not compatible here.

Hope u understand.If not comment here.