this post was submitted on 25 Dec 2025
549 points (96.9% liked)

Programmer Humor

30835 readers
1052 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!

(page 2) 50 comments
sorted by: hot top controversial new old
[–] Wirlocke@lemmy.blahaj.zone 11 points 3 months ago (1 children)

Here's my answer that works with any kind of lightbulb.

Flip switch 1 on, switch 2 off, and get switch 3 stuck in a halfway point which I've done on both lever switches and flat switches.

If it's on it's switch 1, if it's off it's switch 2, if it's flickering or dimmed it's switch 3 and you should probably turn it off to stop damaging the relay.

[–] xthexder@l.sw0.com 9 points 3 months ago* (last edited 3 months ago)

Trying to get a switch stuck half way sounds like a good way to start a fire. If the bulb is dimmed, that means not all the power is making it to the bulb, and half of it is probably going into heating up the switch contacts. It could also be arcing inside the switch, which will also destroy the contacts. I think some new building codes require "arc fault protection" on circuits for this type of reason, in addition to "ground fault protection" (GFCI) on bathroom/kitchen circuits.

[–] fantacyde@lemmy.blahaj.zone 10 points 3 months ago* (last edited 3 months 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."

[–] JackiesFridge@lemmy.world 9 points 3 months ago

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

[–] BCOVertigo@lemmy.world 9 points 3 months 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.

[–] JackbyDev@programming.dev 6 points 3 months 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 6 points 3 months ago (1 children)

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.

[–] JackbyDev@programming.dev 3 points 3 months ago

Yeah, after reading the answers I see it more clearly. Also, I assume in hindsight that it's three switches which can be on or off, so we know if all three are off the light is off. Which helps as well.

[–] Atlas_@lemmy.world 5 points 3 months ago (1 children)

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"

load more comments (1 replies)
[–] Atlas_@lemmy.world 3 points 3 months ago (1 children)

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.

load more comments (1 replies)
[–] Stupidmanager@lemmy.world 5 points 3 months ago

I’ve walked out of interviews that had these popular puzzle questions in the 00s. The company you’re interviewing for is not testing you for your job, it wants a corporate drone that is ok with bureaucracy and can navigate the red tape they’ve put in place.

Really a waste of time, but if I run into this at my age now I ask if they can tell me how their company is making something for the betterment of human kind.

[–] stoy@lemmy.zip 5 points 3 months ago (1 children)

Easy, take a spare phone set up a video call between that phone and your normal phone, leave the spare phone in the lightbulb room.

Go to the light switch room and start flipping switches while looking at your normal phone.

[–] GreenShimada@lemmy.world 3 points 3 months ago

Or with one phone, set it up in a place to see the bulb and take a video. Two options:

  1. with the video recording, scream AS LOUD AS YOU CAN the number of the switch you flip on then off. Hopefully loud enough to hear it on the video. Are you in another building? scream louder!

  2. Start the video recording and you counting 1...2...3... and keep counting on second at a time, in time (or close enough) to the timestamp. Flip on the switches and make note of when you do (e.g. 30-35 sec, 40-45, 50-55) then go back and watch the video.

If it were me, I would do the first one.

[–] workerONE@lemmy.world 5 points 3 months ago

You can get a 66% chance of being right if you turn on a switch and check the room. If the light is off you guess between the other two. For example, you are going to test switch 1 and if it is off you guess switch 2.

Reminds me of the Monty Hall problem except in that problem the game show host has an action to take which effects the odds.

[–] mlg@lemmy.world 4 points 3 months ago (1 children)

Knowing full well this would be coming from a FAANG company, a funnier answer would be to replace the switch with the equivalent smarthome switch, and then spend the next 20 minutes explaining their uttery stupid network pathway from your phone, through the cloud, back to your device to turn on a lightbulb.

[–] lengau@midwest.social 3 points 3 months ago

I once had an interviewer ask me what happens when you type a domain into your browser and hit enter. "Use as much detail as you want."

Well, I did...

"For the sake of brevity, I'll start when the user presses the Enter key. As the key goes down, it makes two contacts connect, passing a current..."

[–] rumba@lemmy.zip 3 points 3 months ago* (last edited 3 months ago)

It depends on what type of person designed the circuit and what type of person you are.

Ergonomics: The switch closest to the door first, then mid, then far, figuring the unknown user would click the switch closest, a skilled electrician would start there. However, it's not unreasonable for the electrician to ask the owner, so this is a hit-or-miss approach.

Installation efficiency: The installer refused to mark any of the lines and instead hooked them up at random, flip in any order, when you find the right one, return the others to the original state.

time efficiency: the energy cost to flip all three switches is minimal and you're only going in once, flip all three at the same time. you've done maximum effort and maximum time savings.

Error reduction, binary counter, all combinations tested in case of chained switching

Debugging: binary counter, followed by checking the lightbulb, possibly swapping for another if one is nearby, checking all the other switches near the room, breakers, power to the structure, and asking an occupant for assistance as a last resort.

Disaster recovery: locate a flashlight or use your phone's torch/flashlight function.

Ahh crap, other room.

  1. ask an occupant

  2. shove a penny in the socket behind the light bulb and listen for a breaker to pop

  3. turn all three on

  4. slide your cell phone under the door with video recording on, stomp on the floor hard every time you flip a switch

  5. turn all the switches through a binary counter looking for one that seems to do nothing.

[–] gtrcoi@programming.dev 3 points 3 months ago

Check the log

[–] iThinkDifferentThanU@lemmy.world 2 points 3 months ago

turn them all on, problem solved

load more comments
view more: ‹ prev next ›