One day, the warden of a prison is, like most wardens in puzzles, feeling a little bit capricious and decides that he wants to get rid of his prisoners, one way or another. He gathers all the prisoners in the yard and explains to them - "Tonight, I will go to each of you, hand you a key, and tell you who has your key. Each day after that, while the others are out of the cells and no one is watching, I will allow each of you to place your key in someone else's cell - and each night, you may collect the keys in your own cell. If, at any point, you are certain that everyone has the key to their own cell, you may summon me, at which point each of you will open your own cell and walk free. If anyone has the wrong key, everyone will be executed then and there. You may discuss your strategy before tonight, but afterwards no communication will be allowed regarding my game. - Oh, and by the way, if you are still here two weeks from today, I will execute everyone - it'll be a big birthday for me and I want to retire!"
That night, just as promised, the warden went to each cell and gave each prisoner a key. As he handed each prisoner the key, he whispered to them the name of the person possessing the key to their cell. The keys were entirely indistinguishable from one another, but that was okay, because the prisoners had not counted on being able to tell anything about them. Indeed, the prisoners all seemed confident.
What was their strategy? How could they beat the warden's game?
We assume the cells in the prison are arranged in a circle. The prisoners agree every day each of them to pass the key they receive to their left neighbor, except for their own key which they keep. It is easy to figure out which key is their own, since they can easily calculate when they will receive it. For example, if prisoner 8 knows that his key is at prisoner 3 in the beginning, then he will get it on the 5th day. Therefore within 10 days all prisoners will have their own keys.