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 table. On top of the table, 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. For this, he chooses some of the barrels and presses the buttons. When he is ready, he shouts “Open sesame!”. If all the lamps are on, the cave opens. Otherwise, the table starts spinning so fast that when it stops it is impossible to tell how much it has turned.

The problem is to determine the values of n for which there is a strategy that guarantees 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 that the table spins.

Solution