Problem 2: Open Sesame! 26 Nov 2023

Ali Baba

This problem always brings me great memories. My favourite part of working on a puzzle is playing around with it with a group of people. Everyone sharing their ideas. That’s how I first heard about this problem, and that’s why I love it so much.

The source for this problem is the Tournament of the Towns in Toronto, fall of 2009, senior A-Level problem 7 (pdf).

The problem

At the entrance to a cave, there is a rotating round platform. On top of the platform, there are n identical barrels, evenly space along the circumference. Inside each barrel there is a lamp, controlled by a button on the outside. The state of each lamp is unknown, and it cannot be deduced from the outside.

Ali Baba wants to enter the cave, and to do so, he must turn all of the lamps on. He can change the state of the lamps by pressing the buttons, and when he is ready, he shouts “Open sesame!”. If all the lamps are on, the cave opens. Otherwise, the platform starts spinning so fast, that when it stops, it is impossible to tell how much it has turned.

For what values of n is there a strategy guaranteeing that Ali Baba will be able to open the cave in a finite number of attempts, regardless of the initial state of the lamps, or the way the platform spins?

Solution