Post:

You have three switches in one room and a single light bulb in another room. You are allowed to visit the room with the light bulb only once. How do you figure out which switch controls the bulb? Write your answer in the comments before looking at other answers.


Comment:

If this were an interview question, the correct response would be "Do you have any relevant questions for me? Because have a long list of things that more deserving of my precious time than to think about this!

  • ilinamorato@lemmy.world
    link
    fedilink
    arrow-up
    25
    ·
    edit-2
    6 hours ago

    Ok. The classic answer is “turn on the first switch for five minutes. Then turn switch 1 back off, turn on the second switch and go in the room immediately. If the light is hot, it’s controlled by switch 1; if it’s on, it’s controlled by switch 2; if it’s off and cold it’s controlled by switch 3.”

    Except that a light bulb in 2025 is very likely to be an LED bulb, so it wouldn’t actually get hot. At least not hot enough to feel even a few moments later. And in a corporate setting (this is classically an interview question), the switch has been more likely to control a fluorescent tube, which can get hot, but typically not as quickly as an incandescent one.

    My answer, if I were in an interview, would be to ask questions (Chesterton’s Fence).

    • First of all, why do we have the one-visit limit? Is this a prod light bulb? We need a dev light bulb environment, with the bulbs and switches in the same room. (While we’re making new environments, let’s get a QA and regression environment, too. Maybe a fallback environment, depending on SLAs.)

    • Second, what might the other switches do? What’s the downside to just turning them all on? If that’s not known, why not? What is the risk? For that matter, do we know that only one switch needs to be turned on to turn on the light, or is it possible that the switches represent some sort of 3-bit binary encoding?

    • Third, why were the switches designed this way? Can they be redesigned to provide better feedback? Or simplified to a single switch? If not, better documentation (labeling) is a must.

    • Fourth, we need to reduce the length of the feedback loop. A five minute test and then physically going to touch the bulb is way too long. Let’s look into moving the switches or the light in our dev environment so that the light can be seen from the switches.