# Temple of lost memories: raiding the circular chamber

In the center room of an ancient temple, there are $$n$$ identical chests. Of these, $$k$$ contain treasure, but the other $$n-k$$ contain mind erasers. You do not know $$k$$. If you open a chest with a mind eraser, you forget everything you’ve learned about the contents of the chests so far. The second time you open the same mind eraser, you’re instantly driven insane.

The room is a perfect circle with no distinguishing features, and the chests are arranged symmetrically around its circumference. You can’t mark chests, change their orientations, or otherwise break the symmetry. You can’t take treasure out of chests, and you must close each chest before opening the next. You can, however, swap pairs of chests as long as the symmetry of the room’s restored before you open a chest.

If you ever open all $$k$$ chests with treasure in a row, the room will fill with magical light, all treasure-containing chests will be flung open, and you will be permitted to take the treasure and return to your homeland.

When your mind’s erased, you wake up in front of the chest, closed like the others, with no memory you’ve opened it. That's also the state you start in. How can you identify all $$k$$ treasures and defeat the circular chamber?

• If you operate according to a strategy, will it be still remembered by you? For example - you never open the chest in front of you.
– Moti
Oct 16 at 5:08
• Is k known to you before you start opening chests? Oct 16 at 6:25
• The question doesn't say what happens when you go insane. Should the final question be "How can you identify all k treasures without going insane?" Oct 16 at 12:56
• What does it mean to identify all k treasures? That at some point you say you stop opening chests and point correctly to all k chests containing treasures?
– xnor
Oct 16 at 18:57
• edited the Q for clarity re: the win condition. agree it was a bit confusing! Oct 16 at 23:58

I claim the following strategy works:

Suppose I remember finding T treasures so far. Shift one chest to the left. Swap that chest T places to the right, then open it. If I find treasure, shift T places left.

How it works:

The idea is to move leftwards around the room, pulling a line of treasure behind me. Whenever I open a new chest, I swap it with the last treasure in line and open it - if it's also treasure, I jump back to the front of the line and progress onward, and if it's a mind eraser, the mind eraser is now behind my treasure hoard. As I resume moving left, I will gradually re-find all the treasure collected so far. Eventually, I'll be in the state I was before getting my mind erased, but with the mind eraser tossed behind the treasure.
The room always remains divided into three regions: Never-opened chests, treasure, and opened mind erasers. I only swap rightward with known treasure, so I can only reach an opened mind eraser by moving left. Since I only progress into new territory one chest at a time, I'll only reach an opened mind eraser after making a full lap around the room, by which time I'll have already found all the treasure.

• I can't visualise how this works at the start. Initially T=0, so you shift left, swap that chest with the one 0 places right (itself), and then open it. If it's a mind eraser, you get your mind erased and start again. On your second go, you haven't found any treasure so T=0 and you repeat, opening the same mind eraser.
– fljx
Oct 16 at 10:10
• So.... you mean you know you've found all the treasure because that last chest drove you insane? Doesn't sound like a reasonable solution, to me. Oct 16 at 12:57
• @HappyDog This solution requires the assumption that you know k - you stop once you have k treasures, so you'll never hit a mind-eraser you've hit before, because you get to it after opening k consecutive treasure chests. There can't be a solution for the version where you don't know k, so it seems a reasonable assumption. Oct 16 at 13:51
• @BlueHairedMeerkat The question has been edited so that opening the $k$ treasures in a row now completes the problem, even if you didn't know $k$. Oct 17 at 1:02