Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For program 7, write MATLAB code to simulate a locker puzzle game. As each student enters for the day, beginning at their locker, they will
For program 7, write MATLAB code to simulate a locker puzzle game. As each student enters for the day, beginning at their locker, they will change the state of some lockers (i.e., if the locker is closed, they will open it, and if it is opened, they will close it). The trick is depending on the student, they will skip over some of the lockers. Read the game details. Game Details: A school has n lockers and n students. All lockers are closed on the first day of school. As the students enter school for the day, the first student (S1) opens every locker beginning with locker one (L1). Then, the second student (S2), beginning with the second locker (L2), closes every other locker (i.e., every second locker). Student three (S3), beginning with the third locker (L3), changes every third locker (closes the locker if it is opened and opens the locker if it is closed). Student four (S4), beginning with the fourth locker (L4), changes every fourth locker. Student five (S5), beginning with locker five (L5), changes every fifth locker. This continues until Student n (Sn), changes just the last^th locker. Requirements: For this program, you MUST use an array to represent the student lockers, and you MUST prompt for n. When finished opening/closing lockers, output which lockers are open and how many times they were opened. Recall that you are keeping track of both the number of times the locker was opened as well as closed. For example, if locker 8 in the lockers array has a value of 11, it has been opened and closed a total of eleven times. However, it has only been opened 6 times. EXTRA CREDIT: Include which locker number has changed the most times, including how many times. On MATLAB, look up the max function. Sample Output: Enter the number of students: 5 locker 1 is open and was opened 1 time(s) locker 4 is open and was opened 2 time(s) Locker 4 was opened and closed the most at 3 times >> Enter the number of students: 100 locker 1 is open and was opened 1 time(s) locker 4 is open and was opened 2 time(s) locker 9 is open and was opened 2 time(s) locker 16 is open and was opened 3 time(s) locker 25 is open and was opened 2 time(s) locker 36 is open and was opened 5 time(s) locker 49 is open and was opened 2 time(s) locker 64 is open and was opened 4 time(s) locker 81 is open and was opened 3 time(s) locker 100 is open and was opened 5 time(s) Locker 60 was opened and closed the most at 12 times >> For program 7, write MATLAB code to simulate a locker puzzle game. As each student enters for the day, beginning at their locker, they will change the state of some lockers (i.e., if the locker is closed, they will open it, and if it is opened, they will close it). The trick is depending on the student, they will skip over some of the lockers. Read the game details. Game Details: A school has n lockers and n students. All lockers are closed on the first day of school. As the students enter school for the day, the first student (S1) opens every locker beginning with locker one (L1). Then, the second student (S2), beginning with the second locker (L2), closes every other locker (i.e., every second locker). Student three (S3), beginning with the third locker (L3), changes every third locker (closes the locker if it is opened and opens the locker if it is closed). Student four (S4), beginning with the fourth locker (L4), changes every fourth locker. Student five (S5), beginning with locker five (L5), changes every fifth locker. This continues until Student n (Sn), changes just the last^th locker. Requirements: For this program, you MUST use an array to represent the student lockers, and you MUST prompt for n. When finished opening/closing lockers, output which lockers are open and how many times they were opened. Recall that you are keeping track of both the number of times the locker was opened as well as closed. For example, if locker 8 in the lockers array has a value of 11, it has been opened and closed a total of eleven times. However, it has only been opened 6 times. EXTRA CREDIT: Include which locker number has changed the most times, including how many times. On MATLAB, look up the max function. Sample Output: Enter the number of students: 5 locker 1 is open and was opened 1 time(s) locker 4 is open and was opened 2 time(s) Locker 4 was opened and closed the most at 3 times >> Enter the number of students: 100 locker 1 is open and was opened 1 time(s) locker 4 is open and was opened 2 time(s) locker 9 is open and was opened 2 time(s) locker 16 is open and was opened 3 time(s) locker 25 is open and was opened 2 time(s) locker 36 is open and was opened 5 time(s) locker 49 is open and was opened 2 time(s) locker 64 is open and was opened 4 time(s) locker 81 is open and was opened 3 time(s) locker 100 is open and was opened 5 time(s) Locker 60 was opened and closed the most at 12 times >>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started