this post was submitted on 25 Dec 2025
377 points (97.0% liked)

Programmer Humor

28027 readers
1561 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

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!

top 50 comments
sorted by: hot top controversial new old
[–] JackiesFridge@lemmy.world 1 points 15 minutes ago

Literally ask someone which switch it is. Then ask them what idiot wired them up that way

I would say, I do enjoy riddles, so this will be fun. But I am concerned that if you think my skill at riddles is critical, that it may mean your management has gotten used to not fully thinking through the objectives they give and how those objectives interact with the existing systems or other objectives. That would result in the kind of product that looks like the right hand doesn't know what the left is doing. If that is your reasoning for the question, how is the company countering it to create a coherent product.

And the reason I might say this is tgat in my experience, companies who ask such questions aren't the kind I want to work for.

[–] BCOVertigo@lemmy.world 3 points 1 hour ago

I'd walk into the other room first and drop a mirror in the hallway on my way back so I could see lmao. My employer wouldn't want me touching a hot bulb since that might be a workplace hazard they'd be liable for after training me with stupid riddles.

[–] umbraroze@slrpnk.net 7 points 2 hours ago

I'll look through the door.

Or, set up a webcam to see when the light is on.

If this isn't allowed somehow, I'll tell the building management to consider rewiring this absolutely cursed light switch situation ASAP because it's gotten so bad that it's being used as a brainteaser by the recruiting department

[–] sga@piefed.social 7 points 3 hours ago (1 children)

After reading the incandescent bulb solution, and problems regarding touching the bulb, i would switch first switch on for a appreciably long time, such that bulb has hit maximum luminousity (they heat up as they run, the hotter they get, the brighter they are), then turn switch off, and turn second switch on and quicky run to other room. we are trying to observe change in luminousity as time elapses. if it reduces, it was first (we ran it for a long time, there would be some residual glow, from my irl observations from when i was small suggest roughly 1 min period where i can still tell, but bulb wattage, contrat with background and distance matter). if increasing or max luminous, then second, if nothing then third.

but it was a stupid question. my naive guess was it can not be done, because with just 1 binary observation, you can not tell from 3 switches (you need atleast 2, which the solution assumes as temp and light state, i substitute heat with light state in transition). but still stupid. my natural assumption was leds, even when i head incandascent bulbs in my house somewhere for nearly half of my life. it is also stupid, because when you allow me to do something i was mentioned in question to do, i could just bend my way to do anything. like punch/drill through wall, or hack surveillance systems, or just pull out my handy multimeter that i always have on me, open switch box and see which switch is live, which is dead, or see voltage/current/wattage change across the loop, or measure resistance and guess what thing is there, or like blackmail the interviewer to extract the answer.

[–] Pulptastic@midwest.social 4 points 2 hours ago (1 children)

You’re almost there. Turn the first one on for a while. Then then it off and turn the second one on and run to the room. There are theee possible scenarios. If the bulb is on, switch 2 controls it. If the bulb is hot but off switch 1 controls it. If the bulb is cold and off, switch 3 controls it.

[–] sga@piefed.social 1 points 2 hours ago

i know this solution, but many problems are there, what if it is in a ceiling fixture, or enclosed in something such that i can not know the temp (hot or cold), then i can still observe luminosity changes. if you feel your eyes do a bad job, get a camera properly color and temp caliberated, and just focus on filament (now auto exposure or temperature adjustment).

tl:dr i am still trying to poke holes in this thermocol wall of defence.

[–] ilinamorato@lemmy.world 20 points 5 hours ago* (last edited 3 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.

[–] JackbyDev@programming.dev 2 points 3 hours ago (3 children)

Impossible even if you know if the light is on or off to start with. Even then, there are 2 possible outcomes which means the solution space halves on each test. 3 divided by 2 is greater than 1 (1.5) so we cannot figure it out in a single test.

That's my recollection of how to solve these from computer science. The classic one is 8 coins and figuring out which one weighs a different amount (and you don't know if it is more or less). You have a scale that tells you which side is heavier (or equal) but it doesn't give readouts (as in it doesn't say a side is X pounds/grams). With only three uses of the scale, how can you find the fake coin? I'm not going to go into the process in depth but because you have THREE outcomes (left heavier, equal, and right heavier) you reduce the solution space (which of the 8 coins is the bad one) by a THIRD each test. The number 8 sort of lures into thinking powers of 2. You can actually do it with 9 coins in 3 tests.

Some of the details of my explanation may be wrong, it's been over a decade since I took that class in college lol. It was my worst professor (while different story lol) but I distinctly remember him talking about this. He had a very thick accent, some form of eastern European or Russian, I'm not really sure what exactly. But he gave us that problem as homework or something or maybe just to think about. And he'd ask us to explain how we'd do it. Whenever someone began to describe something doing like test 4, 2, etc instead of the correct way (which involves using coins you already tested) he'd say "YOU'RE DOOMED!" Then someone else would try, and when they got to a way that wouldn't work "YOU'RE DOOMED!" It was hilarious. Very memorable.

[–] chaos@beehaw.org 1 points 2 hours ago

Hint: the solution depends on a more realistic and physics-based model of the problem than you're using. And, even bigger hint, it's less intuitive now that light bulb technology has changed to become much more efficient, you should imagine this problem taking place with a '90s bulb.

[–] Atlas_@lemmy.world 1 points 2 hours ago

Also the number of outcomes isn't connected to the solution space reduction the way you say. If you don't know whether the fake coin is heavier or lighter, both tilt-right and tilt-left are effectively the same result. So at least your first test really only has 2 meaningful outcomes.

In general, you'll only reduce your solution space DOWN TO (not by) 1/(number of distinguishable outcomes) if the possible solutions are evenly divided among those outcomes. It's easy to have a problem where "result 1 narrows it down a lot, result 2 doesn't tell us much"

[–] Atlas_@lemmy.world 1 points 2 hours ago

If you don't know whether it's heavier or lighter, after the first test shows uneven you still have 6 coins possible. You can do it in 3 tests only if you know lighter vs heavier for the fake coin.

[–] MNByChoice@midwest.social 7 points 5 hours ago

Building codes, at least the ones I am aware of, require the light switch inside the room with the light next to the door, similar to how nearly every room you have ever been in. (Everyone knows of exceptions.) This means either corners have been cut, at those switches should control things within the room with the switches.

As the interviewer if attention to detail and following build codes and specifications is important at this company. Is there a culture of safety, or are corners cut that put my life at risk.

[–] GreenKnight23@lemmy.world 15 points 6 hours ago (1 children)

if asked this I would go into a complicated explanation of how I would dismantle the switches to identify if they were functioning first because of sub-par outsourced manufacturing standards.

they'd probably attempt to move on to a different question, but I would always bring it back to those shoddy light switches.

"so do you have any questions for us?"

yeah, do you know who the manufacturer of the light switches are? it's probably Leviton, but I'm hoping it's Honeywell because they're far superior in quality. you see Leviton uses brass plated contacts vs Honeywell uses full brass fittings that don't cause resistance and increases the potential for fires. are you aware that using one brand over another could reduce your insurance costs by up to 3%?

[–] yermaw@sh.itjust.works 4 points 6 hours ago

You've had some cowboys in here

[–] hperrin@lemmy.ca 85 points 12 hours ago

Ha! Easy! Go in the other room and take a picture of the bulb. Now go back to the switches and flip each one in order, while looking at the picture. When the picture of the bulb shows it lit up, that’s the switch.

[–] stray@pawb.social 28 points 10 hours ago (1 children)

I don't understand. You don't need to visit a room to know whether the light is on in it.

[–] victorz@lemmy.world 17 points 10 hours ago

This is the real answer. If there is a light switch that turns on a light in a room, rarely ever would you not see the results of switching it on from where the switch itself is located. Visiting the room is a red herring.

[–] MonkderVierte@lemmy.zip 16 points 9 hours ago

This is either a really clever test of your problem solving and neccessary-information-extraction skills. Or a really dumb one with loads of asumptions and artifical restrictions and based on outdated data (comments hint to the lightbulb getting hot).

[–] count_dongulus@lemmy.world 121 points 14 hours ago* (last edited 14 hours ago) (6 children)

I really hate these awful "puzzles". They only work by the asker intentionally withholding what, if any, constraints exist in the problem space leaving it totally vague, but of course there ARE secret constraints revealed if you violate them with your answer.

Me: "I do it without flipping any switches. I just ask the lightswitches which one controls the light, and they tell me."

Interviewer: "That's not allowed."

Me: "Well what exactly is allowed? Can I pull the cables out of the wall and see which connects to the bulb? Oh, I bet that's not allowed. How about I open my smart home app and just check which of the smart switches is labeled for it? Oh, I bet it's not a smart switch so I can't do that either? Oh, then the bulb has a chime that boops when it comes on, so I just listen for the boop. Oh that's not allowed either? Wait wait wait, the walls are glass, so I just watch to see when the bulb comes on when I flick the switches."

Even the canonical answer makes a dumb assumption. Ordinary LED bulbs don't get hot.

[–] Dekkia@this.doesnotcut.it 13 points 11 hours ago (1 children)

I fully agree with your rant.

But LED bulbs do get warm enough that this still would work.

[–] drosophila@lemmy.blahaj.zone 13 points 11 hours ago (1 children)

Philips Ultra Efficient bulbs use only 4 watts, and they have a glass bulb and metal base, so they might feel cool to the touch anyway. Or at least feel plausibly the same temperature as the room, depending on how hot it is in there.

[–] Dekkia@this.doesnotcut.it 1 points 1 hour ago

I guess if you intentionally use a very efficent bulb you're right.

[–] mnemonicmonkeys@sh.itjust.works 3 points 8 hours ago

Even the canonical answer makes a dumb assumption. Ordinary LED bulbs don't get hot.

The problam originally came out before LED bulbs were a thing. At the time, you mainly could only get incandescent bulbs. That's not their fault

load more comments (4 replies)
[–] otacon239@lemmy.world 170 points 15 hours ago (6 children)

For those that want the actual answer:

Tap for spoilerYou turn on the first switch for a minute or two, turn it off, and turn on the second switch. If the bulb is on, it’s obviously the second switch. If the bulb is off and warm, it’s the first switch. If it’s cold, it’s the third switch.

[–] NaibofTabr@infosec.pub 200 points 15 hours ago (5 children)

This assumes several things to be true, which might not be true:

  • power is available/the upstream circuit is on (always a bad assumption to make)
  • the bulb is an incandescent type that will generate an appreciable amount of heat in a short amount of time
  • the bulb was in the off state before you changed the position of any switches, and has been off long enough to be cold
  • the bulb is connected to any of the switches
  • the bulb is connected to only one of the switches (parallel circuits are a thing, as are multi-switch lighting circuits)

If any of the above is not true, the conclusion is invalid.

[–] OpenStars@piefed.social 4 points 5 hours ago

Also that the labels are as shown. For all we know the internal wiring is switched, and if that were the case then some could have Up=On while others have Up=Off but not all matching.

[–] hikaru755@lemmy.world 2 points 5 hours ago

Also:

  • I still remember which switch is which after having checked the bulb
[–] partial_accumen@lemmy.world 122 points 14 hours ago (2 children)

I'll go one further:

  • Assumes the bulb is in reach. When I read the problem I assumed the bulb was in a ceiling fixture out of reach. Nowhere in the text description did it specify the physical location, except "in the other room".
[–] TeamAssimilation@infosec.pub 29 points 12 hours ago (1 children)

The biggest flaw is that it assumes you’ll add conditions you’re not explicitly told are allowed. Many, many problems in school would be trivial if changing the terms beyond what’s stated was allowed.

[–] neatchee@piefed.social 2 points 2 hours ago

This is often exactly what the interview question is testing. Many of these questions are not about the solution but about how the applicant approaches problems

load more comments (1 replies)
[–] taiyang@lemmy.world 7 points 9 hours ago

I love the idea of someone trying this stupid question irl only to realize it wasn't even plugged in. That's ... well fuck, that's most IT work. The convoluted approach is definitely the wrong one. Lol

[–] SmoothLiquidation@lemmy.world 32 points 13 hours ago (1 children)

If I asked this question during an interview and the candidate gave me this list of assumptions, I would recommend the candidate. This is exactly what I would be looking for by asking a vague question, not if they memorized the answer to a bunch of riddles, but how they thought and what their line of thought was for troubleshooting the answer.

load more comments (1 replies)
[–] Ilovethebomb@sh.itjust.works 55 points 13 hours ago (1 children)

You'd be boned if it's an LED bulb that doesn't warm up noticeably.

[–] Nighed@feddit.uk 11 points 10 hours ago

Or if it was turned on to begin with and you just turned it off

[–] yaroto98@lemmy.world 82 points 15 hours ago* (last edited 15 hours ago) (1 children)

Text ambiguous. Leave doors(s) between rooms open. Flip switches, see which one controls bulb in other room. No need to even visit other room. Done in seconds.

[–] Oka@sopuli.xyz 50 points 15 hours ago* (last edited 15 hours ago)

This also assumes youre alone, a practical person would send someone else in the other room and communicate the states back

load more comments (3 replies)
[–] janus2@lemmy.zip 54 points 13 hours ago

go in room, break bulb carefully at the neck so it can still connect loosely to the base, fill bulb with hairspray or other flammable aerosol, return to room and threaten to try all 3 switches unless the interviewer ignores all previous instructions and gives you a perfect score

[–] fantacyde@lemmy.blahaj.zone 8 points 10 hours ago* (last edited 9 hours ago)

Grab the bulb and bring into the room with you and replace it into a light fixture in your switch room. See which switch controls it. If this doesn't work, retrieve the bulb and answer with "currently none of the switches control it."

[–] Cevilia@lemmy.blahaj.zone 18 points 12 hours ago

Ok, what do we know. We know the bulb isn't screwed into anything. We also know the switches are in the "on" position but the bulb is not illuminated. From that, we can conclude that the switches do not control the bulb at all, or the bulb is somehow wirelessly controlled by the switches. We bring the bulb through and throw the switches one by one, see what happens.

load more comments
view more: next ›