5

I have a problem called "The Prison Problem" that I need to explain to my 9-year-old cousin. I would think that he has just started learning about divisors and perfect squares, and as such, I have a proposed solution. Any input from you would be welcome, as to what is the best way to go about this.

Problem:

There was a jail with 100 cells in it, all in a long row. The warden was feeling very jolly one night and told their assistant that they wanted to give all the prisoners a wonderful surprise. While they were sleeping, they wanted the assistant to unlock all the cells. This should be done, they told the assistant, by putting the key in each lock, turning it once. The assistant did this, then came back to report that the job was done. Meanwhile, however, the warden has second thoughts. "Maybe I shouldn't let all the prisoners free," he said. "Go back and leave the first cell open, but lock the second one (by putting the key in and turning it once). Then leave the third open, but lock the fourth, and continue in this way for the entire row." The assistant wasn't very surprised at this request as the warden often changed their mind. After finishing this task, the assistant returned, and again the warden had other thoughts. "Here's what I really want you to do," he said. "Go back down the row. Leave the first two cells as they are, and put your key in the third cell and turn it once. Then leave the fourth and fifth cells and turn the key in the sixth. Continue down the row this way." The assistant again did as instructed. Fortunately, the prisoners were still asleep. As a matter of fact, the assistant was getting pretty sleepy, but there was no chance for rest yet. The warden changed their mind again, and the assistant had to go back again and turn the lock in the fourth cell and in every fourth cell down the row. This continued all through the night, next turning the lock in every fifth cell, and then in every sixth, and on and on, until on the last trip, the assistant just had to turn the key in the hundredth cell. When the prisoners finally woke up, which ones could walk out of their cells?

Proposed solution:

Ten cells are left open after this process. Every cell that is a perfect square will remain open (1, 4, 9, 16, 25, 36, 49, 64, 81, and 100). If a number is not a perfect square, then it has an even number of divisors, therefore it will be "toggled" an even number of times and end up where it started (closed). Perfect squares have an odd number of divisors, so they will end up the opposite of where they started (open).

Greg Martin
  • 78,820
  • This video provides a really wonderful visual explanation for the exact problem you are describing. The video only goes up to 90, but provides all the information you need to generalise it to 100. http://www.youtube.com/watch?v=LejoPGtliTs – Pingk Nov 17 '13 at 15:06

2 Answers2

-1

If every cell that is a perfect square will remain open after the process then "The Prison Problem [for 100 cells]" can be rephrased "which numbers from 1 to 100 are perfect squares?"

Another algorithm that can answer this question was posted as a problem (and recently closed) in "Tricky problem - network of light bulbs with non-trivial mechanism" (some_user, 2023).

Newton's Method can also be used to find the roots of f(x) = N^2 for N = 1 to 100. If x is a whole number then N is a perfect square.

The cell index or number can also be generated directly. For n=1 to 100 n^2 is computed. Between (n-1)^2 and n^2 there are no perfect squares because there is no whole number between n-1 and n.

I have a PDF version of this reply that goes into detail plus it includes dynamic and interactive diagrams that allows you to step through each computation of the three mentioned algorithms (Chionglo, 2023).

References

Chionglo, J. F. (2023). Token Games for a Light Bulb with a Non-Trivial Switching Mechanism Plus a Token Game for Newton's Method. DOI: 10.13140/RG.2.2.10445.00480. https://www.researchgate.net/publication/372862568_Token_Games_for_a_Light_Bulb_with_a_Non-Trivial_Switching_Mechanism_Plus_a_Token_Game_for_Newton's_Method.

some_user. (2023).Tricky problem - network of light bulbs with non-trivial mechanism. Tricky problem (full workings shown) - network of light bulbs with non-trivial switching mechanism.. (Jun. 18, 2023).

  • "Newton's Method can also be used to find the roots of f(x) = N^2 for N = 1 to 100. If x is a whole number then N is a perfect square." This makes no sense. – Cheerful Parsnip Sep 02 '23 at 21:14
-2

Your solution is correct, I had to do this for a programming contest, and the problem was extremely similar in it's mathematical nature.