Question

The Lockers Problem There is a well-known mathematical logic problem called the lockers problem. Here is a description of the problem 23 24 25 26 A new high school has just opened! There are 50 lockers in the school and they have been numbered from 1 through 50. When the school opens the first student to enter the school walks into the hallway and opens all the locker doors! Afterwards, the second student closes each door whose number is a multiple of 2. Similarly, the third student changes every door that is a multiple of 3 (closing open doors, opening closed doors). The fourth student changes each door that is a multiple of 4 and so on. After 50 students have entered the hallway, which locker doors are open? Using your BitArray class described above, solve the lockers problem. Each bit in your BitArray should represent a locker, where true is an open locker and false is a closed locker. Once you have finished altering each bit according to the problem statement, print out the number and state of each locker, for example: 1: open 2: CLosed 3: closed 4: open 5. closed 6. closed 7. closed

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The question did not specify language so i have implement it in C++ using array

code :

# include <bits/stdc++.h>
using namespace std;
int arr[51];
int main()
{
   int i,j;
   for(i=1;i<=50;i++)
       for(j=i;j<=50;j+=i)
           arr[j] = 1 - arr[j];       //Flip state of all lockers multiple of i

   for(i=1;i<=50;i++)
       cout << i <<": " << (arr[i]? "open" : "closed") << "\n";
}

Add a comment
Know the answer?
Add Answer to:
The Lockers Problem There is a well-known mathematical logic problem called the lockers problem. Here is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help writing a program for this assignment Problem: Locker puzzle A school has 100...

    I need help writing a program for this assignment Problem: Locker puzzle A school has 100 lockers and 100 students. All lockers are locked on the first day of school. As the students enter, the 1st student opens every locker. Then the 2nd student, begins with the 2nd locker, closes every other locker. The 3rd student begins with the 3rd locker and changes every 3rd locker (closes it if it's open and opens it if its closed). The 4th student...

  • JAVA PLEASE Concepts tested by this program: Variables Input/output .Loops Conditional Statements Methods . Arrays ....

    JAVA PLEASE Concepts tested by this program: Variables Input/output .Loops Conditional Statements Methods . Arrays . Multi-Dimensional Arrays Program 1: Locker Puzzle Problem Description: A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. Then the second student, S2, begins with the second locker, denoted L2, and closes every other locker. Student S3 begins with the third locker and changes...

  • Answer the problem 2 only please. Also if you could upload the excel sheet as well...

    Answer the problem 2 only please. Also if you could upload the excel sheet as well will be very appreciated. thanks OPR 3450 - Fall 2019 Assignment 1 due 09/09/19 page 1 of 1 Assignment 1 This is due in class on multiple dates. Check each Part. Each person must submit his/her own answer. If anyone submits a copy of an assignment, everyone with that submission will get a zero on the assignment. I will not accept e-mail assignments. Each...

  • PROBLEM Mabel is currently working as a swim instructor earning $40,000 per year. Her career goal...

    PROBLEM Mabel is currently working as a swim instructor earning $40,000 per year. Her career goal was to own and operate a swim facilityteaching kids and young adults. When the local swim facility in town was offered for sale, Mabel decided to buy the facility. The facility has a 25 x 50 feet pool, just the right size for swim instruction and comes with a small locker room, bathroom and parking lot. No private bathing stalls are available but an...

  • how the cash here become 1135? because if you check my trial balance the cash is...

    how the cash here become 1135? because if you check my trial balance the cash is 8810. and i can I get help in step 8,9? and I provide u my journal entry this is the steps 8,9 From the information given above, I have solved 5,6,7 that is Adjusting entries, Trial Balance, Income Statement, Statement of Equity changes and Balance Sheet. Der in the problem Set Depreciation expense General in From 1. Sep 131, Dec formoh T unter est...

  • While reading the story, consider the culture (or sub culture) and related communication styles the story...

    While reading the story, consider the culture (or sub culture) and related communication styles the story reveals. Consider too, possibly, the values, behavioral norms, social practices, social artifacts, etc. After reading the story through the lens of this idea, please compose a full academic length (evidence-based 7 to 11 sentence long) paragraph which addresses the following prompt: What does the story reveal about the culture it portrays and/OR the communication styles the culture shares? In other words, what does the...

  • Case Study 1: Should a Computer Grade Your Essays? Would you like your college essays graded...

    Case Study 1: Should a Computer Grade Your Essays? Would you like your college essays graded by a computer? Well, you just might find that happening in your next course. In April 2013, EdX, a Harvard/MIT joint venture to develop massively open online courses (MOOCs), launched an essay-scoring program. Using arti ficial intelligence technology, essays and short answers are immediately scored and feedback tendered, allowing students to revise, resubmit, and improve their grade as many times as necessary. The non-profit...

  • Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen....

    Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen. “Shared Services at RR Communications.” #1-L07-1-002, Queen’s School of Business, September 2007. Reproduced by permission of Queen’s University, School of Business, Kingston, Ontario, Canada. Vince Patton had been waiting years for this day. He pulled the papers together in front of him and scanned the small conference room. “You’re fired,” he said to the four divisional CIOs sitting at the table. They looked nervously...

  • Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen....

    Mini Case Building Shared Services at RR Communications4 4 Smith, H. A., and J. D. McKeen. “Shared Services at RR Communications.” #1-L07-1-002, Queen’s School of Business, September 2007. Reproduced by permission of Queen’s University, School of Business, Kingston, Ontario, Canada. Vince Patton had been waiting years for this day. He pulled the papers together in front of him and scanned the small conference room. “You’re fired,” he said to the four divisional CIOs sitting at the table. They looked nervously...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT