# Turning a fan on

I bought an air purifier which has [off, low, medium, high] settings and a single button. If it is on, the first button press activates the lights and subsequent presses increment the level with off following high. If off, the first press turns activates the lights and increments the level. There is a 30 second cool down before lights turn off. (This is all real world accurate.)

Assuming I was pressing the button remotely and repeated button presses are instantaneous; what is the minimum time it would take me to get the level to a known state and what is the sequence I should follow?

The first thing I came up with is 2.5 minutes.

• That's a crappy fan. Nov 7, 2019 at 12:29

Here is a solution that takes 1.5 minutes.

If the last button press was at least 30 seconds ago and I press the button once, then it is guaranteed not to be Off. If it were Off previously, it will have switched on to a Low level, and otherwise it will have only switched on the lights without changing level.

If the last button press was less than 30 seconds ago, I can press the button $$k$$ times in quick succession, then the level is guaranteed to cycle around $$k$$ steps.

With the above you can eliminate each of the levels in turn until you only have one level left.

Here is what I think is the fastest solution:

1. Wait 30 seconds and press the button. This eliminates Off by switching it to Low.
2. Press the button three more times immediately. The eliminated level is now High.
3. Wait 30 seconds and press the button. This eliminates Off by switching it to Low, so the eliminated levels are Off and High.
4. Press the button three more times immediately. The eliminated levels are now Medium and High.
5. Wait 30 seconds and press the button. This eliminates Off by switching it to Low, so the eliminated levels are Off, Medium and High.
You now know it must be on the Low level. If you want any another level, you can press the button immediately one or more times to reach it. So you can reach your desired level in 1.5 minutes (or 1 minute if you start timing from the first button press).

• Sly! I completely missed the recursive answer. I think this one has it. Nov 13, 2019 at 13:01

What a great first puzzle and nicely related to real life! I can solve it in at most

5 presses or 2.5 minutes

Like so

Notice that the key is to get to the off position. Once in off, we know exactly what state we are in and how to reach any other state. From off the most is 3 presses to reach high. If we start in high then we just need one more press to reach off, so we need at most 4 presses to reach anywhere from high. If we start in medium then we need two presses to reach off, so we need at most 5 presses to reach anywhere from medium. Now if we start in low then we need 4 presses to reach low and 5 presses to reach medium. For reaching high (when starting in low) we can use a clever trick: if we could do 2 presses without reaching off then we must be in high. In all the cases we only need at most 5 presses or 2.5 minutes.