Question: Using Matlab Explaination: You open a random page from a book you selected. The total number of pages in the book is either a 2-digit

 Using Matlab Explaination: You open a random page from a book

you selected. The total number of pages in the book is either

a 2-digit or a 3-digit odd number. The sum of the digits

Using Matlab Explaination: You open a random page from a book you selected. The total number of pages in the book is either a 2-digit or a 3-digit odd number. The sum of the digits in the page number for the righthand-side page is your score for that turn. You keep on doing this until the last digit in the righthand-side page number is a 9 or you have taken up 15 turns, whichever happens first. Your total score is the sum of all the individual scores. Now the other player (Sally) repeats the same process and whoever has the higher total score wins Instructions: Write a function M-file that will simulate this game. The input is the total number of pages (a two or three-digit odd number) in the book you selected to use for the game. There are four outputs for this function. The first two are row vectors that record the page numbers that came up during the play for the two players. The first output is for the player who goes first (My run) and the second output is for the player who goes next (Sally_run,). The third output (winner) gives information about the winner. It can have one of three values, 0, 1 or 2. The value of 0 means the game is tied, a value of 1 means that you are the winner and a value of 2 means that Sally is the winner. The fourth output (win score) stores the final total score of the winner. It is equal to the tied score if the game is tied Generate random integers to simulate the randomly selected page numbers. If the number generated is an even number then consider that as the lefthand-side page number, so that the next number (that will appear on the righthand-side page) will be used as the scoregenerating page number. This corresponding odd number is also used for checking the termination condition (last digit is 9 or not). If the random number is odd then this is used directly for the score generation and termination condition checking. However, store the exact random number generated (odd or even) as elements in the output arrays Note that this means that the presence of both an 8 or 9 at the end of the random integer will serve as a termination condition for a player. Also remember that a player can at most get 15 chances after which he/she must stop even if the last (15th) attempt did not have an 8 or 9 at the end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!