wu :: forums
(http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)

riddles >> hard >> 100 prisoners & a light bulb
(Message started by: Captain Caveman on Jul 23rd, 2002, 10:50pm)



Title: 100 prisoners & a light bulb
Post by Captain Caveman on Jul 23rd, 2002, 10:50pm
Argh, I made the mistake at looking at the 100 prisoners & the light bulb one (under Favorites).  It's driving me crazy... I can't even begin to think of the solution... and there's no hint with it...

Can anybody help?  (hint is nice.  solution is better.  solution w/explanation gets you a gold star ;) )

//Title changed by moderator//

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Ivo on Jul 23rd, 2002, 10:55pm
I've been puzzling over this one as well..  googling doesn't seem to help, yet...  My best guess is that it has something to do with taking a very long time and taking advantage of the fact that the prisoners know how many days it's been since the start...

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Garth Johnson on Jul 23rd, 2002, 11:10pm
Unless it's a trick, I'm sure this is related to probability, which I've nearly forgotten. Initially probably something along the lines of:

don't flip the switch the first time you've been to the room. (after 100 days) Then each subsequent time you've been to the room (or nth time?) toggle the switch to the opposite of what it was the previous time (left the room on last time, leave it off this time). Probability should drop rapidly for each visit where the light encounter is the same as the previous (if on when left and off when entered).

Hmm. this made more sense before I started writting it down.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by mESSDan on Jul 23rd, 2002, 11:17pm

Only turn on the switch if you have never been in the room before.  If you've been in the room before, turn the light off.

If you've been in and the light is on, you know the last person hadn't been in there before.  As soon as you've been in the room atleast 99 times with the light being on, you've got it.

I like the fact that I'm probably wrong ;)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by BanderSnatch on Jul 23rd, 2002, 11:19pm
My first thought on this is rather simple, though in reality it would (most likely) take far too long to be practical.  Starting the day of the meeting, each prisoner starts counting the days.   As each prisoner goes into the room, they leave the light in the off position.  However, if they have been in the room once before in the hundred days, they turn the light on.  Once the light is turned on, it stays on for the remainder of the initial hundred days as a signal to the others that someone has been in the room more than once, and hence someone will not have been in the room at the end of the hundred days.  On the hundredth day, the prisoner turns the light off, starting another hundred day cycle.  If, on the last day of any hundred day cycle, the light remains in the off position, it can be said with certainty that every prisoner has been in the room, since no prisoner has been there twice.

Though this solution would eventually work, probability says that it would not work in a timely manner, since it goes in 100 day cycles, rather than having the possibility of the hundred days starting at any arbitrary time.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Ivo on Jul 23rd, 2002, 11:33pm
Hm, well, a few people have suggested solutions that'll take significantly longer than the prisoners' life spans to work...  However, the best one I can come up with is "Wait 3 years and assume (with 99.5% accuracy) that everyone's been in the room"....  Anyone got a better solution?

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Captain Caveman on Jul 23rd, 2002, 11:34pm
Well... inelegant, but certainly workable.  At least I can go to bed now without it bothering me too badly.

Since the page doesn't indicate he's missing the solution for this one, I hope Mr. Wu is kind enough to post his solution here.... I keep wondering if there's a really simple easy one or something.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Daleks on Jul 23rd, 2002, 11:35pm
First off, the problem statement never says whether or not the prisoners can see the light flickering in their cells. I'll assume they can. Also there will come a time that all prisoners will have entered the commons area. Whether or not they die before that time comes is a problem, but I'll ignore that.

Anyway, my idea is to have each prisoner remember the number of times the light was flicked on/off the night before--call it n. If they have never been in the commons area before and are selected the next day, they flick the light n+1 times. If they have been in the commons area before and are selected, flick the light n times. And of course if they're not selected, sulk in their cell. So the person that enters the commons area and would have flicked the light 100 times can merely tell the warden everyone has been inside. You could also just not flick the light at all if you're a repeat, but people might forget.  ;) Also of course n starts at 0.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Captain Caveman on Jul 23rd, 2002, 11:36pm
Err, I meant the 100-day cycle one was inelegant but workable.  It'd take forever, but at least you'd be *certain*, which is the impression I took from the way the riddle is posed -- you'd be CERTAIN your answer was correct.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Captain Caveman on Jul 23rd, 2002, 11:39pm
Hrm, the counting flickers is interesting.  I just assumed the "solitary" bit meant that they were totally isolated.

These are really the kind of questions you need to be on a one-on-one basis so you could ask questions like that of the riddler... "Can they see the light from their cells?" ("Yes" "No" "irrelevant")

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Captain Caveman on Jul 23rd, 2002, 11:46pm
Ok, here's 2 i snagged quickly from /. that I like.

1:  Designate 1 person to turn the light off.  Everyone else, on your first time in the room, IF THE LIGHT IS OFF, turn it on.  (Otherwise, leave it on.)  After the designated person turns it off 99 times (or 100, if he turns it off for himself...), he can demand their freedom.

This works even if they can't see the bulb from their cells and is rather elegant.

2:  If they can see the bulb, instead of flicking it a whole bunch of times, just flick it once on your first time in the room.  After the 100th flick, demand freedom.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by SPEEDenator on Jul 23rd, 2002, 11:50pm
The solution works IFF (that's the iff and only iff bit there) in a given 100-day cycle, all 100 prisoners go in... there are plenty of patterns (granted, not necessarily random :) that foil it:

day 1: prisoner 1 goes in
day 2 - cycle in order prisoners 1 - 100

Thus, there's always 1 person who will have seen the light twice in that cycle.

-e

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by BanderSnatch on Jul 23rd, 2002, 11:53pm
If the light could be seen by each inmate, it would make the problem quite trivial.  The idea posted earlier of flicking the light n number of times would work, but would actually be overly complicated.

Assuming the inmates can see the light from their cells, they would simply have to set up the following system:

If you have not been in the room before, turn on the bulb for a set time and turn it back off.

If you HAVE been in the room before, do not turn on the bulb at all.

The prisoners count the number of times the bulb comes on.  After they count to 100, everyone has been in the room.

Problem:  The riddle states that the bulb may be toggled, but it does not say how many times.  If the inmate may only toggle it once (ie from off to on, or on to off), this plan would not work without modification.  In which case the following ruleset would be better:

If prisoner has not been in the room before, they turn the light on and leave it on.

If prisoner HAS been in the room before, they turn the light off, and it stays in the off position until another inmate turns it on.  Inmates must then only count the number of days the light is on.  Once the number reaches 100, everyone has been there.

The problem with both these very similar solutions is that both assume, possibly (probably?) incorrectly, that the inmates can see the light from their cells.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by SPEEDenator on Jul 24th, 2002, 12:14am
Men-in-Black Solution:

If the lightbulb is off, turn it on.

First time in the room, carve a "I" into a wall. When there are 100 "I"s, you're done.

Last one out turn off the light. :)

The "99 turn offs until you're done" I think amounts to 100! if the distribution is close to cylcical (i.e. say guy 1 is turn-offer, if it goes 1 .. 100 and then cycles again, it'll be 100!). But hey, after 100! days, they'll all be free. :)

-e

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by DTM on Jul 25th, 2002, 1:16am
This one had me going for a bit too.
I really think Captain Caveman has the essence of the solution, however since the guards take a prisoner at random, you are wasting a lot of time waiting for the designated person to show up to start the whole thing off.
The prisoners should decide that whoever is the first prisoner to enter the room after their huddle is the leader (as  'elected' by the guards).
He turns on the light, and is the only person allowed to turn on the light.
Each and every other prisoner turns off the light if and only if the light is already on and if they have not already done so.
When the leader turns on the light for the 100th time (this includes the first one), time to be free! Of course, as the leader has to himself/herself return to the room 100 times, it could take over 27 years...
Slightly better yet, they could choose that whoever enters the room on the 2nd day after their meeting is the 'elected' leader, and declared freedom when he turns the light on for the 99th time (he assumes the light was off when he got in on day 2).  If it's the same person on the 2nd day as the 1st, then it's the same as the first solution, otherwise they can save one leader cycle which could last from a few days to a hundred (or far more) days.
I think the best that this can be optimized is to have the person who enters the room on the 3rd day, the elected leader.  The first person turns the light on.  If he's also the person in the room on the 2nd day, he leaves it on.  Otherwise, the 2nd person turns off the light.  The third person  (or 'elected' leader) needs to turn on the light 98 times if he comes in with the light off, 99 times if the light is on, or 100 times if the guards were nasty and made it the same person for the 1st three days...
If there is another improvement, I can't think of it at this time!

Note: As they are in isolation, it is unlikely that they can either see the flicker (besides, they'd have to be fully and continuously aware - doubtful if your left in isolation for too long !) And they better pray there isn't an electrical storm or that the bulb doesn't burns out during the minimum 100 days! Then again, if a prisoner dies somewhere along the way, they're doomed!

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by scodger on Jul 25th, 2002, 5:12am
The prisoners are allowed to get together one night, to discuss a plan. What plan should they agree on, so that eventually, someone will make a correct assertion?
it doesnt say it has to be the firdst day, maybe this is the key

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by knox on Jul 25th, 2002, 6:13am
Yes a hybrid might be a good way.

Say just wait for hundret days. Then make the meeting night. Now you can count how many people have already been to the room and how many are missing. I think with random chances ~50% of the people should have been in the room already. (after 200 days 75%, etc.)

So you should calculate when you get the shortest time in result to make metting time, this is where probality caluclation comes in.

Okay after meeting night you have two groups, the ones who have already been in there and the ones who havent.  Then you can do the leader system as descriped before. Or is there something better? Those who have been in there before meeting night of course don't touch the light any more.The ones who havent turn the light on if it's off and they haven't yet turned it on. The leader turns it off everytime he is in. After he turned it n times off he can demand freedom.

--

For the theories where the prisoners can see the light from the cells, they don't need to "flicker" it at all (so breaking the rules). Just toggle it over the first time you are in the room. (if it has been on turn it off, it has been of turn it on) After they have seen it hundret times toggling they can demand freedom safely.

--

Then there is a pragmatic way also, just wait say 365 days without caring about the bulb at all and then demand freedom to take your chances, A year prision is long enough. (or two years or three, etc. your chances go better).

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by dmachine2 on Jul 25th, 2002, 8:18am
Well, they're allowed to meet all together one night.  Why not meet in the living room?   :P  It's probably the only room that can hold all the prisoners anway ;)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AGirl on Jul 25th, 2002, 9:11am
The fastest way to get the cons out (without resorting to weasles like marking things on the wall or being able to see the light) I can find is the following:

Info: 100 cons, 1 bit info transfer, random selection of cons.

You can only work in cycles of 100 days. Someone posted that solution already, but in stead of resetting every cycle you should reset but keep counting cycles.

The cons agree that they do not swich on the light, unless they have visited the room more than once in the first cycle. If the light is switched on by someone, the cons know that soemone has been in twice and that at least one person has not visited the room. They have to wait until the end of the cycle and don't do anything.

The first one to start the second cycle switches off the light if he has been in the room twice or less (twice, because it's the second cycle). The light stays out unless someone comes into the room who has been in the room three times or more. Then the light goes on. If the light is on, it stays on for the rest of the cycle and the cons, again, know that chances are that at least one person has not been in the room and do nothing. In the third cycle the light only goes on if someone has visited 3 or more, in the 4th cycle 4 or more, etc.

If OTOH, at the end of a cycle, the light is out (i.e. every con has visited the room a number of times that is equal or less to the number of cycles that have passed) the first con of the next cycle can declare freedom.

This solution is better than the one posted where the cycle just gets reset every time, because in that case you have to wait until the random selection happens to pick every con exactly one time within a 100 day cycle.

This solution does not require that, as it keeps track of the number of cycles and thus minimises the number of repeats required.

It can still take a long time, but speed is not a requirement of the riddle. Accuracy is. "Taking your chances" is not a valid solution.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by DTM on Jul 25th, 2002, 11:29am
All I can say is, poor prisoners!

So far, two workable solutions given a reasonable definition of solitary confinement.

The 'leader' solution could take 27 years, while either of the 100 day cycle ones might never occur.
In the first variant, as AGirl pointed out, it takes that all 100 prisoners get perfectly distributed over an arbitrarily fixed 100 day period.  While the second variant isn't necessarily better as it requires a different perfect distribution in that each prisoner enters the room n times in a arbitrarily fixed set of n*100 days.
Both systems are at the mercy of the jailers.  I might be more tempted with the 2nd 100 day cycle solution if I knew that the warden was using a pseudo-random number generator (it generally NOT being truly random) thus more likely to be uniformly distributed. This one seems better suited for a computer algorithms than real life.

I prefer the leader solution as it doesn't require that every prisoner keep track of exactly how many days they've been in solitary confinement (a difficult task at best!). Plus, it can take advantage of the scodger/know variant of waiting before the first meeting, which I can't see it being of use to the 100 cycle day variants. Granted, it is less likely to have a quick resolution...

Anyone have a valid third solution that doesn't require 'cheating' by seeing the light while in solitary confinement? (I like the idea of having the meeting in the living room!)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by DTM on Jul 25th, 2002, 11:34am
All I can say is, poor prisoners!

So far, two workable solutions given a reasonable definition of solitary confinement.

The 'leader' solution could take 27 years, while either of the 100 day cycle ones might never occur.
In the first variant, as AGirl pointed out, it takes that all 100 prisoners get perfectly distributed over an arbitrarily fixed 100 day period.  While the second variant isn't necessarily better as it requires a different perfect distribution in that each prisoner enters the room n times in a arbitrarily fixed set of n*100 days.
Both systems are at the mercy of the jailers.  I might be more tempted with the 2nd 100 day cycle solution if I knew that the warden was using a pseudo-random number generator (it generally NOT being truly random) thus more likely to be uniformly distributed. This one seems better suited for a computer algorithms than real life.

I prefer the leader solution as it doesn't require that every prisoner keep track of exactly how many days they've been in solitary confinement (a difficult task at best!). Plus, it can take advantage of the scodger/know variant of waiting before the first meeting, which I can't see it being of use to the 100 cycle day variants. Granted, it is less likely to have a quick resolution...

Anyone have a valid third solution that doesn't require 'cheating' by seeing the light while in solitary confinement? (I like the idea of having the meeting in the living room!)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by dabicho on Jul 25th, 2002, 3:26pm
My solution.
The leader toggles each time he enters, except if  its different than the last time he entered.
Others, toggle first time, and dont toggle subsequent times.
Then... then what?
I think  im on the right trail but...

heeeeelp!

(besides my work, the best nice solution ive read so far was the meeting at the living room  ;D)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by sjbrown on Jul 25th, 2002, 7:09pm
I think I've found another solution.  (the only other two so far were the "Leader" solution and the one where it's off on the 101st (or 201st or 301st ...) day. )

100-day Months
Pretend every month has 100 days.  Each prisoner is assigned a day of the month.  You only switch on the light if you're in the room on your day, otherwise you switch the light off.  If the light is on when you go in the room, you know prisoner d has been in the room.  When you've seen the light on on *every* day of the month, you know every prisoner has been in the room.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by dj on Jul 25th, 2002, 9:05pm
I assume
(1) The prisoners get together once at the beginning
(2) They can see the light from their cells
(3) You only get to toggle once per visit to the room

Solution:
If you enter the room for the first time, toggle the switch.
If you enter it again, don't do anything.

From your cell, count the toggles (on-to-off or off-to-on).  That's how many prisoners have been there at least once.  If yours would be the 100th toggle, everyone has been there.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by italic on Jul 25th, 2002, 9:55pm
could someone please post the solution? I am of the opinion it has to be one of the two following possibilities:

(1) - the one leader who counts each unique toggle. this would take a long, long time statistically, but this is most likely the best bet.

(2) - The night of the meeting is held in the main room, so the first person picked can assert they have all been there. I hate this idea (as it doesn't say anywhere that they meet anywhere specific) but I am slowly starting to wonder if this isn't the answer.

You can play around with binary counting all you want, but you need to have 1 person in charge for those toggles to mean anything.

Please, someone post the solution. or at least email it to me. it's driving me crazy!

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Rhaokarr on Jul 26th, 2002, 1:07am
I don't have a problem with the 'leader' solution - after all, the problem does use the word 'eventually'.

I'm also not sure why things can only be done in sets of 100 days. Sure, you need a minimum of 100 days to get all the prisoners through (meaning that for the leader solution, you need 199 days - the leader has to enter once for each new entry by another), but once you pass that minimum, there is nothing particularly magical about the number 100 in terms of days spent.

Just pray that the guy in on the first day isn't big Bubba who has the intellectual capacity of fried lard...

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Kozo Morimoto on Jul 26th, 2002, 1:09am
Maybe we could start by looking at a case where number of prisoners is small.

if the number of prisoners = 1, this is a trivial case.
if the number of prisoners = 2, again, this is a trivial case.
How would you do it for 3 prisoners?  How would you do it for 4 prisoners?  Can you then extrapolate to n=100?

What information do the prisoners have:
1) number of times he/she has been in the living room.
2) when he/she was in the living room (ie which days since the meeting)
3) the binary semaphore of the previous prisoner to be in the living room.

Any other info?

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Kevin on Jul 26th, 2002, 2:43am
Take a situation with 4 prsisoners.  Number the days as follows:
1
1,2
1,2,3
1,2,3,4
(total of 20 days).
Each prisoner goes into the room and only turns (or leaves)the light on when he/she knows that the current day number is equal to (or less than) the number of prisoners that have been into the room.  Otherwise, the prisoner turns the light off.

If you go through it on paper with some people (A,B,C,D) trying various combinations of prisoners, repeat visits etc, you find that eventually each prisoner builds up knowledge of the number of people that have been into the room based on the state of the light when they enter.  When somebody goes in on day 4 and the light is on, bingo.

Extrapolate this to 99.... is it quicker than 27 years??  Of course, after a while you don't really need the lower numbers, so perhaps the system can be refined a bit.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by srowen on Jul 26th, 2002, 7:11am
I believe I have the answer. It does not assume things that probably aren't implied by the problem, like that the prisoners can see the light bulb from their cell, or that they can gather after the first day.

The idea is that the prisoners will use the state of the light switch to (gradually) communicate information about who has been in the cell, from one day's prisoner to the next, until someone knows for sure that they've all been in there.

The night before, they gather and assign themselves numbers from 0 to 99. They then agree on the following rules for what to do in the room:

1) Let D be the current day. If you know that prisoner # D(mod 100) has been in the room, leave the light on. If you do not know that, leave it off.
2) If the light was on when you came in, then you know that prisoner (D-1)(mod 100) has been in the room before - remember that.

For example, if I am prisoner #59, and go in on day 845, and I see the light on, I know that #44 has been in there. Furthermore, if I know that #45 has been in somehow, then I leave the light on to spread that info to the next day's prisoner.

This process only gets started when some prisoner X goes in on a day that is equal to X, modulo 100 (i.e., #33 goes in on day 433, and since he obviously knows that #33 has been in the room since he's there now,  he leaves the light on. If tomorrow, #78 walks in, now #78 knows that too).

Eventually the info will spread enough so that someone knows for sure everyone has been in the room.

I ran a little simulation, and with 100 prisoners, it takes them about 95,000 days on average to know they've all been in there (though on average they will all have visited after about 450 days).

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by biwema on Jul 26th, 2002, 7:42am
Hi,

At the moment I don't know a better 'save' solution than this one with the prisoner who counts the people by only switching off the light. As they have to wait for 27 years on average, I would gamble a little bit if I were in that situation.

To be a little bit more sure, I use the switch as parity counter. Every prisoner toggles the switch only the first time when he goes to the room.

after one year, the probabilities are:

100 people have visited the room ~97%
99 people have visited the room ~3%
98 people have visited the room 0.085%
97 people have visited the room 0.002%

So, if after one year the light is off, it is 99.9% probable that everyone has vistited the room. If the light is on, it is 99.9% probable, that exactly 99 people have been in the room (97 people: 0.09%). In that case that person who hs not been to the room yet, can make the statement, that now everybody has been there when he visits the first time.

I think tis is much better than 27 years even if there is a small risk remaining. If you are a coward, just wait 2 years. The probability of being killed is 1/1000000 then.

hope that helps

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by srowen on Jul 26th, 2002, 8:05am
I think the problem is asking for a mechanism by which the prisoners can be 100% sure that all have visited, instead of a probabilistic answer.

In a matter of just years, the probability would be extremely small that there was still someone who hadn't visited. So prisoners could take this gamble approach without any prior discussion, or any use of the lightswitch whatsoever, and get out in a few years.

See above for a 100% solution (albeit one that takes centuries!)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Enladio on Jul 26th, 2002, 9:16am
I think the trick to this question is the line that states "he needs to murder no more than 10 prisoners".  Thus, you have up to 10 prisoners to play with.

Here's the way I see it,

Divide the 1000 bottles by 2, and assign 1 prisoner to each half.  Divide each half by a half and assign prisioners to each new half.  Divide the halved halfs by a half and assign a prisioner to each new half. Continue dividing by a half till your left with 1 prisioner assigned to 1 bottle.   You will noticed, if you count the divisions, that there are up to 10 division (some cases less).

If you have your prisioners drink this way, up to 10 will be murdered and you will have found the poisoned bottle.

One question though, this method uses almost 10 times the number required if you assigned one prisioner to one bottle.  So, I don't beleive it's the final solution.

Any other ideas?

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by srowen on Jul 26th, 2002, 9:21am
You are talking about a different problem!  ;D

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Salem on Jul 26th, 2002, 2:33pm

on 07/25/02 at 09:11:53, AGirl wrote:
 The fastest way to get the cons out (without resorting to weasles like marking things on the wall or being able to see the light) I can find is the following:Info: 100 cons, 1 bit info transfer, random selection of cons.You can only work in cycles of 100 days. Someone posted that solution already, but in stead of resetting every cycle you should reset but keep counting cycles. The cons agree that they do not swich on the light, unless they have visited the room more than once in the first cycle. If the light is switched on by someone, the cons know that soemone has been in twice and that at least one person has not visited the room. They have to wait until the end of the cycle and don't do anything. The first one to start the second cycle switches off the light if he has been in the room twice or less (twice, because it's the second cycle). The light stays out unless someone comes into the room who has been in the room three times or more. Then the light goes on. If the light is on, it stays on for the rest of the cycle and the cons, again, know that chances are that at least one person has not been in the room and do nothing. In the third cycle the light only goes on if someone has visited 3 or more, in the 4th cycle 4 or more, etc.If OTOH, at the end of a cycle, the light is out (i.e. every con has visited the room a number of times that is equal or less to the number of cycles that have passed) the first con of the next cycle can declare freedom.

This solution does not work. Imagine the following distribution:
First 100 days:
1 poor guy gets selected 50 times
50 guys (call them "group a") gets selected once
Second 100 days:
48 previously unselected people get picked twice
4 people from group a get picked

Nobody in the second group was picked twice, and yet there is still
one person who has not been in the room.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by waka on Jul 26th, 2002, 9:37pm
Here is my answer for the question, which I believe is correct.  It is a variant of the leader solution previously proposed.

The prisoners all gather the first night a choose a leader.  They impose the following rules:
- When any person other than the leader enters the room for the first time, they may turn the light on if it is off.
- When the leader enters the room, he adds one to his count of prisoners that have visited the room if the light is on.  He turns the light off before he leaves.
- When a person who has previously turned the light on enters the room and finds the light off, they may not turn it on.

When the leader's count reaches 99, he knows that every person has visited the room.  The light being on means "at least one new person has visited since my last visit."

Yes, this will take a long time.
Yes, it is a solution, as the question says nothing about a time limit.

This can be proven with a simple case of 4 prisoners:

Say Person #1 is the leader.
The light starts out off.

First, person #3 goes in.  He finds the light off so he turns it on.

Next comes #4, #3 again, and #2.  They all see that the light is on so they do nothing.

After this, say #1 comes back in.  Since he is the leader, he finds the light on and adds 1 to his count (making his count "1").  He turns the light off.

Next #3 comes in again, but since he previously flipped the switch, he leaves the light off.

After that, say #4 comes in.  The light is off and he hasn't turned it on before, so he turns it on.

Then, #2, #3, and #4 all come in several times.  They all leave the light alone because it is on.

The leader, #1, comes in again and finds the light on, so he adds 1 to his count, making it 2. Again, he turns off the light as he leaves.

Next come in #4 and #3, but since they have both flipped the light, they leave it alone.

Eventually, #2 comes in again, but since he hasn't flipped on the light yet, he turns it on.

After this, any combination of #2, #3, and #4 can come in.  They will all leave the light alone as it it already on.

Finally, when #1 comes in again, he sees the light is on, so he adds one more to his count, making it 3.  Since he can count himself as well, he knows that all 4 people have visited the room at least once.  He can now declare with absolute conviction that they have all visited the room.

Note that the number of prisoners and the order they come in doesn't matter.  Expand this to 100 prisoners or N prisoners, and it should work.

waka

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Mark Ebden on Jul 27th, 2002, 10:20am

Hi,

I like Waka's solution, although for N=100 it will of course take several decades to execute.  If the leader happens to arrive in the room in short intervals (< 100d) at first, and longer intervals (> 100d) later on, the prisoners can get out in less than 20 a.  If the reverse occurs, they'll be there for over 50 a.  Average should be 30-something years.

Now let's think about that.  An average of more than three whole DECADES.  Compare it to the probability-focused answer earlier, in which prisoners were let out in two years with 99.9% certainty, or, not as good, let out in one year with 97% certainty.

Taking a vote amongst the 100 prisoners, how many are going to say, "well, that 0.1% chance is big enough that I will waste my life in jail instead"?

Exactly.  So I think the real answer to this riddle is, "Any solution that requires 100% certainty runs the risk of taking too long.  Hence, the probabilistic approach is best."

But I do like Waka's solution if we need precision.

Cheers,

Mark

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Mark Ebden on Jul 27th, 2002, 10:22am

Testing... not sure if the last message got through.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by cnmne on Jul 27th, 2002, 10:34am
If they just waited a few years, and occasionally flicked the bulb to pass the boredom, these would be the odds that a prisoner was never selected, with a leap day after 3 years:

1) it would be a miracle.
2) 93.48833%
3) 99.83549%
4) 99.99580%
5) 99.99989%

Technically, there is always a chance that a prisoner is not selected, even after they all die of boredom (or old age).  Being criminal masterminds, they probably choose five years and 1/100000 odds over a life sentance and accuracy.

If they are criminal retentives instead, the carry bit prisoner (one guy flicks off and carries 1 bit register overflow, everyone else flicks on first visit) is a real solution.  Assuming average distribution, 27 years seems a long time to wait.  After half that time the odds that they have all been in the room are a lot better than the odds of a spaceship crash landing on the prison.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by cnmne on Jul 27th, 2002, 10:47am
above are the odds that all prisoners visited the room, not that 1 prisoner did not. :-[

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by srowen on Jul 27th, 2002, 11:00am
I like Waka's solution more than mine as it appears to work faster. It also guarantees success, which is the intent of the problem, I imagine.

I think it needs one tweak though:

"- When any person other than the leader enters the room for the first time, they may turn the light on if it is off."

Should this not be:

"-When any person other than the leader enters the room, and has never turned the light on, they may turn the light on if it is off."

It's not just the first time they enter, as they may enter for the first time while the light is on.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Eyal Peer on Jul 27th, 2002, 6:28pm
Waka's solution does not work.
You can always find a pattern in which everyone has used their "First time - turn on" option, but no one ever counts 100.

I know, since I thought of a solution just like this myself untill some mathematician I talked to disproved it.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by waka on Jul 27th, 2002, 11:07pm
srowen-
Yes, you are correct.  A prisoner is only allowed to turn on the light iff they have never turned it on before.  Sorry, that should have been more clear.

Eyal-
I remain unconvinced that my answer is wrong.  Can you provide an example (or even better, a proof) of when my solution fails?

As I stated before, nothing about the riddle states that it must be completed in a certain amount of time.  Frankly, I don't care what the context of the problem is... the riddle is not asking for a solution that is the most realistic.  It is asking for a solution that is 100% reliable, given infinite time.  I don't find the probability solutions adequate because they fail to answer the riddle... they are solving the context and not the riddle's requirements.

So, if my solution does indeed fail, I'd love to know when!

waka

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by tim on Jul 28th, 2002, 12:20am
Waka: Your answer works with probability 1.  To a mathematician, that is not the same as saying that it always works :)

One example where it fails is if the leader is only ever picked 90 times.  Yes, the probability of such a sequence goes to zero as time goes to infinity, but there are an infinite number of infinite sequences that have this property.

In fact, there is technically no guarantee that all prisoners will ever visit the living room.  Again, the probability is zero, but "probability zero" does not mean "impossible".

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Salem on Jul 28th, 2002, 6:49am
Here is a modified solution which could cut down on the expected time it would take for the prisoners to get out.

It is based on the "leader" idea, but you get a good jump start :)

The first person to go in the room 2 times is the "leader".
He turns on the light. If he goes in for the second time on
day 65, then he knows 64 prisoners have been in the room.
Nobody does anything else until the 100th day.

Note: this first set of 100 days creates four groups of prisoners:
Group A) inmates that entered the room for the first time and the light was off.
Group B) inmates that entered the room for the first time and and the light was on
Group C) inmates that did not enter the room
Group D) the leader who entered the room twice and turned on the light.

The person that gets picked on the 100th day has a special job. If they are from group A or group D, they turn off the light. If they are from group B or C, they leave the light on.

After the first 100 days, the solution is just like the "leader" solution. Here is what each group does the next time they are selected:

Group A) nothing, they have already been counted
Group B) turn on the light the next time they enter the room and the light is off
Group C) turn on the light the next time they enter the room and the light is off
Group D) turn off the light if the light is on, decrement the number of people left to enter the room.

This could cut off a significant number of

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by dlau on Jul 28th, 2002, 11:22pm
I like my friend's solution, where everyone defecats in the corner once, and when there are 100 pieces, the prisoner will tell the prison guard. :D (or a slightly more reasonable soln of breaking the lightbuib into 100 pieces)

David

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by johnP on Jul 29th, 2002, 2:05am
Heh, I'm no expert, but these are my thoughts on the subject:

1) There's no way to make sure all the prisoners will be picked by the warden. No matter how many years pass, you can never be 100% sure all the prisoners get picked.

2) Each of the 100 men live in solitary cells. When you consider that they are allowed to hold one meeting, while remembering how small a solitary cell is (certainly not big enough to hold 100 persons, assuming it's not some crazy hotel-sized solitary cell), it's sort of obvious that the only place to hold the meeting is in the living room.

Thus, the prisoners should agree to meet on day one. Then they will all have visited the central living room, and they're all free to go.

Another solution is equally simple: When a prisoner is picked to go to the living room, he stays there (in other words, he doesn't return to his cell). After 100 days, they talk to the warden. This solution is worse though, since it takes 100 days for them to get out of prison. It however covers the possibility that the prisoners are supposed to visit the livingroom AFTER the meeting they're allowed (the meeting doesn't count as a visit).

I might be totally wrong here of course. Maybe there is a solution? But if each man goes back to his cell after visiting the living room, I can't see how it's possible to make sure they all visit the living room. It sure is likely in the long run, but not much to base an escape plan on. They simply cannot devise a plan when someone eventually will be certain that 100% of the prisoners have visited the room.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by francois on Jul 29th, 2002, 5:37am
I ran some tests :
1 prisonner/day approach (with knowledge propagation) : about 100000 days
wait for 100 day cycle were each prisonner has gone in the room once : too long

I think Salem's variant on the leader approach is interesting but wouldn't yield that big an improvement for N=100 as you'll probably only have a 10 to 20 person headstart (rather than the 64 in the example).

I've tried variants on the 1 prisonner/day approach: more generaly instead of associating one prisonner per day, you could associate a group of prisonners in order to spread the information faster among all prisonners. For example (for N=4):
day 1 : {1}
day 2 : {2}
day 3 : {3}
day 4 : {4}
day 5 : {1, 2}
day 6 : {3, 4}
day 7 : {1, 2, 3, 4} // actually this one is a bit stupid
However testing showed it's generally worse than the basic approach.

I wonder if there's a significantly better solution. I think this riddle is very interesting but not very "riddlish" - I don't think there is a clear solution. It has more of a information theory problem feel.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by David Gómez Noguera on Jul 29th, 2002, 6:56am
here is a new solution, based on a propagation solution posted here.
each prisioner will be asigned a number, corresponding to a day on a 100 days cycles.
Prisioner 1 will turn on the light if he enters on the first day of the cycle, always.
Prisioner n will LEAVE the light on ONLY IF:
he entered on day n and the light was on (duh!) thus meaning that prisioners 1 through n-1 have been in.
he entered on day k, and some other day he entered on day k+1 and that time the light was on (thus meaning that he knows prisioners 1 through k have been in) (of course, if he does not know, but it has happened before, the prisioner k+1 wouldnt know... error probability)

Then after a 100 day cycle, prisioners could roll numbers so that 1 is now 100, and 2 is 1... and 100 is now 99.

Have never been good at probs, so i dont know  the odds.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Salem on Jul 29th, 2002, 7:04am
Francois,
My modification may "only" buy you 10-20 prisoners, but that is 10-20
cycles which have an expected period of 100 days. That is some
significant time when you are in jail :)

Also, the modification gives you a (very small) chance of getting out in 100 days.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Gamer555 on Jul 29th, 2002, 8:26pm
Phew! So is nobody (besides maybe Eyal) protesting the "leader" solution (turn it off and add one to count if on)

PS: Tim is right. No solution (besides the silly ones) will work, cause the warden could just not ever put 1 prisoner into the room! Oops! If we had a guarentee that SOMETIME all prisoners would be put into the room (which I think we'd have to assume) we could use the 'leader solution'.

Phew! 3 pages isn't easy to read! 8)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by tim on Jul 29th, 2002, 8:46pm
No, it needs a stronger guarantee than that.  For example, if one prisoner goes through once only, and it happens to be when the light is already on. The leader will never count that prisoner. In fact, the same prisoner could go through a million times with the light on (consecutively if necessary) and still not be counted.

You need a guarantee more along the lines that no prisoner will be scheduled to go to the living room only a finite number of times. This is true with probability 1 for any infinite random sequence, so isn't too restrictive.

Title: Every prisoner will enter the room at some point
Post by srowen on Jul 29th, 2002, 8:55pm
Yes, I agree - this is given in the problem since the warden selects prisoners "at random", presumably meaning uniformly at random, blah blah blah. We don't have to worry that some prisoner will never make it in there, or can only make it in there a finite number of times.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by tim on Jul 29th, 2002, 9:12pm
I'll just reiterate my earlier comment that to a mathematician, "probability 1" does not mean "always" :)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by pa0pa0 on Jul 30th, 2002, 10:43am
Salem's modification of the leader method is extremely nice.

But it might still be advisable to decide on the leader during the initial meeting, choosing the person who appears to be youngest and/or healthiest.

Loss of the leader before they get out causes certain disaster;  loss of other prisoners only might cause disaster, depending on whether they die before or after they have been counted by the leader.

Are the prisoners allowed to ask for a computer during the initial meeting, to run some actuarial simulations?  That would help them decide whether Salem's modification buys them a shorter expected time that outweighs the greater risk.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by johnP on Jul 31st, 2002, 4:55am
Would someone please explain to me why this "leader theory" would work? If the group selects a leader, there's a chance that in a million years, the leader (or anyone else) won't even be picked ONCE. I thought the text asked for a solution where the prisoners can be sure to get out. This shouldn't even take too many years... "infinite time" is nice in theory (but no guarantee for the leader theory to work), but you can't apply infinite time to this exercise as a real-life problem. It's been said by some here in the forum that the leader theory "guarantees success". This is a random selection! Who knows? The same person might be picked a billion times in a row. And then a billion more times in a row. Et cetera.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by pa0pa0 on Jul 31st, 2002, 8:48am

on 07/31/02 at 04:55:52, johnP wrote:
 The same person might be picked a billion times in a row. And then a billion more times in a row. Et cetera.

Please tell me exactly *how* many times in a row you are talking about.  You haven't given a number, you've just given a vague indication ("et cetera") of what you mean.  Well, of course, I *know* what you mean, but that's not the point.  The point is, that you cannot specify any sequence of warders' choices that would give a basis for your conern, except by giving a *rule* (of the form, for example, "choose the same person every day").  But the warders are not allowed to use a rule!  The riddle says that!  (That's what "random" means).

So your concern is baseless.  (There are, actually, questions about whether it is physically possible to generate a truly random infinite sequence.  Better send the riddle back to the makers.)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by johnP on Aug 1st, 2002, 4:55am
Sure thing. With random selection, it's possible for the same person to be picked as many times in a row as possible. "Infinitely" many times. And I'm not talking about a "rule", I'm talking about possible outcomes of random selections. When you elect a leader, a person that has to picked a number of times (100 or whatever), the problem is that no matter how many times you make a random selection from the prisoners, you don't have a guarantee that any prisoner will be picked - not even once. So how can you base an escape plan on that? An escape plan with a 100% guarantee of success? That's not possible. If you presume that every person will be picked, and the leader will be picked 100 times etc etc, THAT'S when you're applying a rule to the selection process. Random means there are no guarantees for who gets selected, when they get selected, if they ever get selected at all. And if you take this as a serious problem, you'll even have to get the prisoners out before they all die - there's no such thing as "infinite time" in this case. In "infinite time", there's a HUGE chance of all of them getting selected a HUGE number of times, but you can't base a watertight solution on it. I'm not using a rule to prove the "leader theory" is wrong, I'm simply telling you why it's wrong (if I'm right ;) ).

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by tim on Aug 1st, 2002, 5:41pm
The leader method does have a 100% chance of success. It just isn't infalible. To a mathematician the terms are not synonymous.

The problem asked for a 100% chance of success, and that's the condition that is satisfied. It is not infallible, just 100% likely to succeed. There is 0% chance of failure, but failure is still possible.

This may be confusing to those uninitiated in the deeper mysteries of mathematics ;)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by johnP on Aug 1st, 2002, 10:34pm
Well, if that's correct, I suppose you might be right. I just intuitively thought a 100% chance was a guarantee that something would happen, and a 0% chance meant something would never happen. Maybe the problem should have an "M" next to it, as in "requires mathematical knowledge" or whatever that M means? :)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Luni_B on Aug 1st, 2002, 11:41pm
100 Prisoners and a Light Bulb

i have the absolute optimal answer to this riddle...

the VERY first person selected asserts that all 100 have been to the living room, and everyone will be let go...reguardless of whether he chooses to turn the light on

because they all had to meet in the living room to make the plan...100 people don't fit in any of the 1 person cells, hence, the living room!

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Rhaokarr on Aug 2nd, 2002, 12:27am
To the 'They've all been in the living room once at the meeting' arguments: The question does not state that they were allowed to get together in the living room - they may have been assembled in an exercise yard, or perhaps a mess hall.

I think the spirit of the question is also reinforced by the use of the word 'eventually'.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Charlie949 on Aug 2nd, 2002, 1:50pm
Without using any of the previous assumptions, I have come up with a couple of ideas:

1. I think that only one, predetermined person can be the prisoner to state that everyone has been to the room. It should be the first person to revisit the room, namely, prisoner X. He/she is determined by having the first prisoner turn on the light on Day 1 and having person X turn it off. He/she will then know how many people have been in exactly once. Let's say this number is 10 (i.e. X revisited the room on Day 11). The next person to turn it on will be a) somone who has never walked into the room when the light was on AND b) someone who has never turned on the light. The next time X walks in and sees the light on, he will know that at least one new person has walked in since he was there last. X turns off the light and we repeat this process. Unfortunately, this example would take a minimum of 90 visits by X (10 original prisoners, 89 others and X), but it is sure-fire.

2. I am fairly certain that there is no way for any two (or more) specific prisoners to share information. If X wants to tell Y something by leaving the light off, Y wouldn't know if X left it off or hasn't been in at all.

Forgive me if these ideas overlap someone else's.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by mook on Aug 2nd, 2002, 4:11pm
charlie- the problem your theory is that more than one person will assume he's the leader. The first one who enters twice will flick the switch off, and assume he's the leader(correctly). Now, say that the next prisoner has never been in the room before, he turns the light on. The next day, someone who has already been in the room enters for the second time finding the light on, he too will flick it off thinking he's the leader.

The leader theory does require that he is picked at least 99 times to have been in the room after a different person has turned the switch on(or off, it doesn't really matter which way the switch needs to be left by the leader- he can trun it on, and if a new person finds it on he'll turn it off, and only the leader turns it on, or the leader turns it off, and no else can), but it does seem to be the only theory that will eventually be 100% accurate.  To shorten that time, i like the having the meeting after x amount days, but assuming the meeting has to be beforehand, I think you can do better than the 2nd day leader. You can say whoever's selected on the third day is the leader. The person on the second day will have an important task, however, he must leave the switch on if he is coming in for the first time, and off if he came in on both days. This way the 3rd day leader would have to be selected to go into the room a minimum of 98 times as opposed to 99.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by jmlyle on Aug 2nd, 2002, 10:16pm
Tim wrote:

Quote:
 The problem asked for a 100% chance of success, and that's the condition that is satisfied. It is not infallible, just 100% likely to succeed. There is 0% chance of failure, but failure is still possible.

Not quite. Here's what the problem states about the assertion that all prisoners have been to the room:

Quote:
 the assertion should only be made if the prisoner is 100% certain of its validity

The requirements say nothing about the certainty that this situation will ever occur. And it says nothing about finding an answer with a 100% chance for success.

And johnP said:

Quote:
 If you presume that every person will be picked, and the leader will be picked 100 times etc etc, THAT'S when you're applying a rule to the selection process. Random means there are no guarantees for who gets selected, when they get selected, if they ever get selected at all.

Well, I grant you that it's possible that at least one person might never get picked, but it's extremely unlikely as time goes on (to put it mildly). But it doesn't really matter, because as long as at least one prisoner has never gone into the room, then the only options for everyone are to stay in prison or get shot.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by dan on Aug 3rd, 2002, 7:22am
charlie's solution works, but within the first 100 days once the light is turned off nobody else should be allowed to turn it on so that nobody else will think he is the "leader".

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by mook on Aug 3rd, 2002, 7:43am
you say no one else is allowed to turn the switch, but still, the prisoners won't know who the leader is, so they won't know that they're the else.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 4th, 2002, 9:49pm
"First person in twice is the leader", proposed earlier in the thread by Salem, does work correctly and is nearly as good as it gets as far as I know. We can save a few extra days by not having the leader finding session last 100 days, but rather have it go for 29 days. The chance that we get more than 29 people going in before the first repeat is so small that we're better off taking the 71 extra days than hoping for that long shot (in terms of getting the lowest expected time served). That modification saves us about 68 days,  but we're still left with the same ballpark of 25 years. Scroll back up and read salem's description, he lays out the different cases pretty clearly if you have any doubts.

The probabilistic answers aren't what was asked for but they are good points since they would be far superior if the prisoners were willing to take some risk for the gain of freedom.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by tim on Aug 4th, 2002, 10:48pm
jmlyle:
Quote:
 The requirements say nothing about the certainty that this situation will ever occur. And it says nothing about finding an answer with a 100% chance for success.

Yes they do.  The problem says "What plan should they agree on, so that eventually, someone will make a correct assertion?" (Emphasis mine)

Use of the word "will" indicates certainty of a future event. That is: given the strategy, there must be a 100% chance that its requirements for making an correct assertion are met.

Fortunately that holds for the proposed leader solutions. It is possible for no assertion to be made, but such an event has probability zero and hence does not break the problem's requirement.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by OMG on Aug 5th, 2002, 5:21pm
:o
When to call the meeting?

There can be no meeting until all prisoners agree to it.
Solutuion #1 (If they are truely Mensa members)
When the last prisoner agrees to a meeting, then they can be freed.
Do not agree to meet until you have been to the room!
If you all are prisoners with me, then I am already dead meat!

Solution #2 (I am the only "leader" / Mensa member)
I will only agree to a meeting after waiting the optimum probability number of days. (I would figure them out, but I am not in prison; I have better things to do, and I leave the details of which to you Math wizards/Mensa members.)  Then I would finally agree to a meeting, and ask each prisoner if he has been to the room.
The number should be small by this point, and as leader of this select squad sized outfit (who haven't yet been to the room) I would get a real mathmatician amongst us to solve this smaller problem, then some math genuis can determine that only the odd man should turn the light on.  While my squad counts the days, and toggles the light, the rest of you prisoners should just wait to be saved by dividing the problem into a solvable number.  The warden will do the "work" for us, as you all wait for me to solve it.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Captain Cannibus on Aug 5th, 2002, 11:25pm
OMG,

how would the prisoners know not to agree to a meeting until having been in the living room if they haven't been to the meeting to talk about their plan yet? the prisoners don't know what any of the other prisoners are doing until the meeting.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by OMG on Aug 6th, 2002, 5:09am
:D

Captain Cannibus wrote:
"how would the prisoners know not to agree to a meeting until having been in the living room if they haven't been to the meeting to talk about their plan yet? the prisoners don't know what any of the other prisoners are doing until the meeting."

Answer:  It would be common sense for Mensa members.

Solution 1) If all the prisoners are really MENSA material, they would only make the "assertion" for the meeting (in the one room that will fit them all, BTW) if only they themselves been to the living room before; hopefully they can be 100% certain of this.  I cannot prove that it is optimal, but it is foolproof.  Must I alone must have the willpower to not meet until I have solved the entire riddle?

Solution 2) I am only one prisoner,
and I do not agree to meet until I am ready;
all the rest of you prisoners may do as you please, until I save you.  It will take much longer, therefore it is not optimal.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by dabichon on Aug 6th, 2002, 10:09pm
This is a very simplistic solution.
Each prisioner will be asigned a number from 0 to 99.
On the x day, if it is the x prisioner who enters the room, he will turn on the light, so the next one knows he has been there.
Now, each prisioner is allowed to turn on the light if its his turn OR if he knows that prisioner has been there,
so if i knew prisioner 20 has been in the room, and the next cycle i happen to enter on day 20, i will turn the light on, even though i am prisioner 54.

Hey!  most of these algorithms can be programmed with threads and all mighty powerfull "C".
Anyone?
::)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by S. Owen on Aug 7th, 2002, 6:58am
This is the answer I gave a while ago... while I like its elegance and egalitarianism because there is no leader, it ends up being much slower than the "leader" solutions posed above, especially with some of the suggested enhancements.

This process just takes a long time to get going, although once it does, info spreads very quickly. I did a little checking and the 100 prisoners will get out in about 260 years on average, compared to a matter of a decade or so for other solutions.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 7th, 2002, 10:42am
I have a solution which takes about 3900 days ( <11 years) on average, compared to ~10000 days ( >27 years) for the "leader" solution. It's similar, except there is more than one prisoner counting:

1 prisoner is designated Master Counter, 9 prisoners are designated Assistant Counters. Call the rest of the prisoners "drones". The light is initially switched off.

Stage 1 is similar to the "leader" solution. It lasts for 2600 days:
-The first time a drone enters the room and finds the light switched off, he switches the light on. After that, he doesn't touch the switch until the last day of Stage 1.
-If a Counter enters the room and the light is on AND he has not already counted up to 9, he adds one to his count and switches the light off. If he has already counted up to 9, or the light is off, he does nothing.
-On the last day of Stage 1, whoever visits ensures that the light is off before he leaves, unless the visitor is an Assistant Counter who has counted up to 9, in which case he ensures the light is on.

Stage 2 lasts for 2700 days. In this stage, the Master Counter counts the Assistant Counters who managed to count up to 9 in Stage 1. Call these ACs "complete", the other ACs are "incomplete":
-Drones and incomplete Assistant Counters do not touch the switch until the last day of Stage 2.
-If one of the complete Assistant Counters happens to be the person who entered the room on the last day of Stage 1, he does not touch the switch until the last day of Stage 2 (because he will have already left the light on).
-All other complete Assistant Counters switch the light on the first time they find it switched off during Stage 2. After that, they do not touch the switch until the last day of Stage 2.
-If the Master Counter enters the room during Stage 2 and the light is on, he adds one to his count of complete Assistant Counters (a separate tally to the one he used in Stage 1) and switches the light off. In other words, The Master Counter counts the "complete" ACs in a similar way to Stage 1. Once he knows that all Assistant Counters plus himself are complete, he announces to the Warden that all prisoners have visited the room.
-If they get to the last day of Stage 2 and the prisoners still haven't been freed, whoever visits the room that day ensures the light is switched off, all the Counters reset their counts to zero, and the entire process starts from scratch the next day.

You can adjust the number of Counters, the length of Stage 1, and the length of Stage 2, and perhaps get a better result. I just picked the values 10/2600/2700 by trial and error, they seem to work well.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 7th, 2002, 12:37pm
Good idea Paul. I don't want to have to compute the exact expected time or optimal parameters of that method on paper but it does look like its a fair bit faster than the leader model.

I think you don't actually have to start from scratch if you get to the end of the second round with a failure. Just go back to stage one and everyone remembers what they did before, so that only drones who haven't flicked the switch and incomplete counters participate (it would probably be best to have shorter stage times as you go on). The one tweak you'd need for this that I can see would be that if the light was on at the end day of stage 1, and the person in the room wasn't an unfilled counter, then he would have to remember that fact and account for it by turning on the light 1 time (1 extra time if he was an unused drone)  during the next stage 1.

It seems like as n grows you might be able to work this idea into something like an O(n (log n)^2) solution.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 7th, 2002, 12:54pm

on 08/07/02 at 12:37:08, AlexH wrote:
 I think you don't actually have to start from scratch if you get to the end of the second round with a failure. Just go back to stage one and everyone remembers what they did before, so that only drones who haven't flicked the switch and incomplete counters participate (it would probably be best to have shorter stage times as you go on).

Hmm... but there could be some drones who "signalled" in Stage 1, but don't know that they were counted.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 7th, 2002, 1:08pm
The drones can consider themselves counted if they ever sent a message. All messages must have been recieved except for that one that might waiting on the last day of stage 1. This is why we need to have the person who goes in on that day behave differently. If he isn't an unfilled counter (and thus able to count the message himself), then he takes on the extra duties of that 1 drone whose message was never counted because of the end of stage 1 (in addition to whatever other duties he performs). This actually applies to all stages (so that if the light was on at the end of stage 2, the person who saw it must turn it off and take on the additional role of filled counter in stage 2 the second time around).

Edited to add: We might need slightly more than O(n (log n)^2) due to the way the probabilites work out, but not too much more. Divide the prisoners into one half drones, one half counters. At each new stage make half the counters into drones (and all old drones are completely inactive). The sum of expectation times for success in all stages is O(n (log n)^2) , but we may need to stretch the stages a bit more for each new stage we add in order to control the probability of failure. We can easily bound this stretch by log n giving us O(n (log n)^3), but I think a careful analysis could probably do better. In any case this method is asymptotically much better than the single leader model.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 7th, 2002, 3:31pm
"All messages must have been recieved except for that one that might waiting on the last day of stage 1"

You're right, I had overlooked that.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 7th, 2002, 7:19pm
Random additional tweak to the n (log n)^2 method. If we're doing this in binary,  we don't actually have to designate who are drones and who are counters in advance. Everyone starts as active. If an active person enters the room, they toggle the light switch. If it was initially on they call themselves a counter and stay active in the next stage (though they do nothing further during this stage). If it was initally off they call themselves drones and then become inactive from that point on. Of course anyone, whether active or not, has to do the turn off and account for it next time through if the light is on at the end of the stage. This doesn't change anything asymptotically, but it saves a factor of 2 in expectation.

If I get a chance later I'll type in a bit of explanation as to why we can achieve O(n (log n)^2) performance overall. The key is to look at the variance of expected time to finish a stage and then use that to show that the amount we have to extend each stage as we increase the number of stages is very small and winds up disappearing in the notation because the total extension to all earlier stages combined is about the same as the extra time needed to add one more stage.

I glossed over this problem because I first saw it in a similar version but where we specifically couldn't assume anything about the timing of visits (no 1/day rule).  Its a lot more interesting because of that change. We now have a solution which gives theta(n (log n)^2) expected performance, which is pretty close to the expected (n log n) time it takes for the statement to be true at all. Pretty darn cool  ;D

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 7th, 2002, 9:45pm
I wrote a bit of C++ code to describe the algorithm and it turns out the special last day stuff just folds in very nicely and makes it very clear whats happening. Here is the relevant part:

public:
bool haveWeWonYet(){
return (myCounter & (1 << numberOfStages));
}
// goToRoom returns new status of lightOn after prisoner has been to room
bool goToRoom(unsigned stageBit,bool lightOn){
if (lastDayInStage){
if lightOn
myCounter += stageBit;
return false;
}
if (myCounter & stageBit){
if (lightOn){
myCounter += stageBit;
return false;
}
else {
myCounter -= stageBit;
return true;
}
}
else
return lightOn;

}

Everyone's counter starts at 1. If the number of prisoners isn't a power of 2, we can correct that just by adding in the leftover (2^m - #prisoners) into some prisoner's initial counter.

Reading code snippets would be easier if tab characters took a bit more room within a tt tag. Is it possible to adjust the default for that at the server?

It seems like it might be possible to do slightly better by using a digit size which grows (slowly) with n instead of a fixed digit size (in this case 2).

The binary method is really pretty IMO, but upon reflection, I think we could get away with a digit around size log n and nudge our asypmptotic performance to O(n (log n)^2 / log log n)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by pa0pa0 on Aug 8th, 2002, 7:10am

Each person starts with one (conceptual) token, and we set up

(a) rules, by which people can transfer some or all of their tokens to each other, and
(b) a policy, such that the tokens tend to accumulate in fewer hands.

Inherent in the rules will be the fact that a person can only transfer tokens by being in the room, so as soon as anyone gets 100 tokens, end of problem.

Each day is associated with a power of 2 as follows: take the day mod 64, and associate it with the largest  power of 2 by which it is divisible.  Thus, for example, all odd days are associated with 1, and day number 208 is associated with 16;  and the largest number associated with any day is 64.

Because of ascii limitations, we shall write 2eN for 2 to the power of N.  Thus, for example, 2e5 means 32.

Now, the rules are very simple:

On a day associated with 2eN, the person in the room may,
if he has at least 2eN tokens, transfer them all to the next
person by leaving the light on;  if he chooses not to,  or if
he doesn't have that many tokens,  he leaves the light off.

Next, we need a policy so that the tokens don't go aimlessly wandering from one person to another.

Definition: a person's collection of tokens is grouped into blocks of tokens such that each block is a power of 2, and each block is as large as possible.

Thus, for example, a person with 40 tokens has a block of 32 and a block of 8;  he doesn't have a block of 16, nor of 4, nor 2, nor 1.

Now, the policy is: transfer tokens if and only if you have them as a block.  Thus, a person with 40 tokens will decide to transfer 8 (if the day is correct), or 32 (if the day is correct), but no other number.

The effect of this policy is that, considering all the blocks in the system as a whole, the number of blocks never increases, and it decreases by 1 every time that a person receiving a block of tokens already happens to have a block of the same size (since he then automatically coalesces the two blocks into one twice as large).

To finish the problem off, we add that when any person acquires 51 or more tokens, he becomes the leader and never thereafter gives any tokens away, but only accumulates them.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 8th, 2002, 7:31am

on 08/07/02 at 19:19:56, AlexH wrote:
 If I get a chance later I'll type in a bit of explanation as to why we can achieve O(n (log n)^2) performance overall.

Alex, I would be interested to see that.

(bear in mind that, while I understand your terminology, I am not a Computer Scientist, so if you could aim it at the "mathematically literate layman", that would be nice  :) )

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Jonathan_the_Red on Aug 8th, 2002, 9:23am

on 08/08/02 at 07:10:43, pa0pa0 wrote:
 Definition: a person's collection of tokens is grouped into blocks of tokens such that each block is a power of 2, and each block is as large as possible.Thus, for example, a person with 40 tokens has a block of 32 and a block of 8;  he doesn't have a block of 16, nor of 4, nor 2, nor 1.Now, the policy is: transfer tokens if and only if you have them as a block.  Thus, a person with 40 tokens will decide to transfer 8 (if the day is correct), or 32 (if the day is correct), but no other number.

In other words, treat each prisoner's tokens as a binary number. Each day is associated with a single binary bit. If the prisoner's binary token count has that bit set, flip it to 0 and pass it to the next guy.

Quote:
 To finish the problem off, we add that when any person acquires 51 or more tokens, he becomes the leader and never thereafter gives any tokens away, but only accumulates them.

I like this idea, and I think it has possibilities. Unfortunately, I ran some simulations, and it turns out that it has an average escape time of about 2,500 years. The problem is that larger blocks (especially blocks of 32) move very, very slowly. Maybe there's some way to improve it.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 8th, 2002, 10:22am
Perhaps you could use stages with this method too, because after a while there will probably be no 1-blocks left. So in Stage 2, the day-number scheme would go 2-4-2-8-2-4-2-16 etc. Stage 3 would assume that all the 2-blocks have disappeared, and so on.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 8th, 2002, 11:50am
Only have a minute right now, but:
Paul-- I'll try to post that proof later today.

pa0pa0--Thats an interesting idea to explore but I think it has some fundamental problems. If I understand you, you're sending the same sorts of messages as in the binary stages solution but you're interleaving all the sending/receiving instead of breaking things into long stages where the same bit position is traded. Think about how long it takes to send the last few messages for any given bit position. For example lets say we're down to having the last 2 prisoners with 1 bits in position 1 and we need them to combine. These 2 bits only combine when one of the prisoners enters 1 day, and the other enters the next. Now which prisoner is holding these bits will shift around, but at each time there will be 2 prisoners with such bits and the odds of getting 1 after the other is 1 in (n choose 2) and it has to happen on a day with the right label, which is another 1 in (log n).

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 9th, 2002, 9:05am
Here is the argument for the binary stages method being O(n(log n)^2). I think its not quite as good as a log n style digit size asymptotically,  but its a great deal prettier in terms of implementation. Its also fairly parsimonious about certain things which weren't asked for but which I find kind of interesting. If we were concerned about wearing out the light bulb with excessive switching then binary would be very good. It takes < 2n flicks if it succeeds in the first pass (and only slightly more if it doesn't) putting it about even with the leader model (while being much faster). We could also imagine that the light bulb (or whatever 1 bit item we use to communicate) is difficult to access. With the exception of the (log n) stage ending days, no prisoner actually has to go look at the switch other than times when he has to go flip it. So, if r is the number of rounds (i.e. full passes through all stages) in the algorithm then the necessary number of trips to see the bulb room is < 2n + (2r-1) log n. On to the proof ...

Assorted basic facts I'll use:
Variance (or mean) of the sum of independent variables is sum of variances (or means).
Geometric distribution with probability p has mean 1/p and variance (1-p)/p^2.
Sum of harmonic series H(n) =(approx) ln n
Sum of series of 1/i^2 (I'll call that H_2(n)) converges to pi^2/6.
For p in [0,1]: (1-p)^n >= 1 - np
Less than 1/k^2 of a distribution can be > mean + k * (deviation)
ln and log_2 are off by a constant factor so I won't be distinguishing between them.

In stage i we start with a = n / 2^i  active prisoners (prisoners with stageBit = 1) --- I only really need that a<=n which is obvious. Every time an active prisoner is selected by the warden, he flips his bit and becomes inactive for the rest of the phase. Each reduction in the number of active prisoners is an independent geometric distribution with p=(a/n) where a is the current number of active prisoners.Observe that the sum of means is nH(a) and the sum of variances is < H_2(a) * n^2, so these are the mean/variance of success of the stage as a whole. Lets say we want at least a 1-1/2log n chance of success for the stage. We can ensure this by waiting (mean) + sqrt(2log n) * deviation < n log n + sqrt(2log n) * n * pi/sqrt(6). This is O(n log n). If we have log n stages, then the odds that all will succeed are at least (1-1/(2log n))^(log n) > 1 - (log n)/(2log n) = 1 - 1/2 = .5 and the total time needed is O(n (log n)^2). Since each pass through all the stages wins with p>.5, we average < 2 passes and the total expected time for success is O(n (log n)^2).

Here is the code snippet from my working test model. There is a little extra complexity on stage ending days, but overall its very simple. On 100 prisoners it takes about 4500 with my arbitrarily chosen stage length parameters. On 256 it takes 14800 or so on average and on 4 it takes about 20. Better parameters might improve those times by a bit (probably not more than 10 percent or so). In practice # days is  c(n) * n (ln n)^2 where c(4)<3 and drops as you increase problem size with c(128)<2. I think c drops to something like 1.5 asymptotically with current parameters.

bool prisonerToRoom(int prisoner, bool lightOn){
currentDay++;
if (currentDay == stageCutoffs[currentStage]){

if (lightOn) { // prisoner must absorb unreceived message
myCounter[prisoner] += stageBit;
}
stageCompleted(); // stageBit changes here

// commence the next stage
if (myCounter[prisoner] & stageBit){
myCounter[prisoner] -= stageBit;
return true;
}
else
return false;
}
else if (myCounter[prisoner] & stageBit){
if (lightOn){
myCounter[prisoner] += stageBit;
return false;
}
else {
myCounter[prisoner] -= stageBit;
return true;
}
}
else
return lightOn;
}

Edit: corrected a typo.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Ilia Denotkine on Aug 9th, 2002, 2:00pm
well, my idea is this:

the first prisoner breaks the light bulb and puts all the fragments in one pile, but one in an other one. the next visitor (unless he has been in the room before) puts an other fragment in the second pile. When someone sees that there is exactly 100 fragments in the second pile, they can all be set free.

I guess my idea could make the most optimal solution ;D.

Only my brother said that if the guardians of the prison see the light bulb broken, they will replace the light bulb AND the prisoners (or kill them) :-X.

By the way, who would want some bright prisonersfree???

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Don Rowe on Aug 9th, 2002, 3:31pm
I think you do it like this, although the question is a bit ambiguous:  Assume that the order the prisoners go into the room is the same each day.  Therefore the instructions to each prisoner are, if you enter the room on the first day, toggle the light, and remember whether it was on or off when you entered, which constitutes the first bit (lsb) in your prisoner order number.  The next day, only toggle the light if the light was on when you entered on the previous day, and remember whether the light was on when you entered, which is the next bit in your number.  Keep going all week, and each prisoner will have a number.  One prisoner's number will be 100 (110000b), and he's the guy.  One caveat - the light will still be on at the end of some days, and if it isn't reset, the prisoners whill have to figure out and remember which, and flip their numbering bits accordingly.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 10th, 2002, 12:02am
Don I think you might have misread the problem. Only one prisoner goes in each day, and he is selected at random so there is no pattern to the order in which the prisoners enter the room.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 10th, 2002, 12:32am
Thanks for posting that explanation, btw. I totally agree with you about the elegance of the binary method, it's really nice. Would almost be a shame to use a larger digit size even if it is faster; it gets messy then.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 10th, 2002, 8:34pm
Sadly, the universe doesn't seem to reward beauty in this case. The approx log n digit solution does beat the binary solution, giving O(n (log n)2/log log n) and winning out even in practice. For 100 prisoners its a close run thing between [5,5,4] vs [10,10]. I don't have a full simulation for the variable digit but I do have a statistical analysis simulation (which you need as part of the simulation anyway since you need to know how long to make the stages). [5,5,4] saves about 330 some days in sum of expectations vs [10,10], but it has to pay for the extra stage in terms of buying greater error tolerance and in gaining less from an early victory in the final stage. Until I have a full simulation, (assuming I get the time to make one  :-/) I won't know if it wins or not but they will be very close, and both a bit faster than binary.

As n grows you can see the advantage of the log n digit solution kick in. For example with 4096 =(approx) e8.3 prisoners using [8,8,8,8] beats binary by about a factor of 2, and also beats [16,16,16] by a factor of 1.7 or so.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by jeremiahsmith on Aug 12th, 2002, 11:18pm
You're all wrong. What the prisoners need to do is start a riot during their meeting in the living room, overpower the guards, and escape that way.

Sometimes, it's best to think outside the box.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Dave Lockwood on Aug 14th, 2002, 4:16am
I have a solution - the catch being it would take rather a long time to carry out (but then that's implied in the question - if the warden only picks prisoners at random, then it could take forever before all 100 prisoners have been to the room).

The solution is split into two phases - the first 100 days, and then the rest of time (!!!) The reason for this will hopefully be evident in the explanation.

The light is initially off.
First  100 days:
Everyone follows the same set of instructions:
The first time you enter the room, do not toggle the switch. In the exceedingly unlikely event that it is day 100 and the light is off - go tell the warden it's party time!
If you enter the room a second time (during the 100 days) - switch the light on if it is off. If it is already on, do nothing.
Once the light is on, no one switches it off during the rest of the 100 days.
Therefore, only  one person  switches the light on during the 100 days - this person is now "The Counter" and is the only one who can eventually assert that all 100 prisoners have been in the room. On  day "n" when The Counter switches on the light, The Counter knows for certain that (n-1) prisoners have been to the room (1 prisoner per day, no repeat visits by anyone up until today).
If it is day 100, switch off the light.

Rest of time:
If you entered the room during the first 100 days and the light was off: Do nothing - you've already been counted.
If you entered the room during the first 100 days  only when  the light was on, or if you didn't enter the room during the first 100 days:  The next time you enter the room when the light is off, switch it on. On all subsequent visits, do nothing.
If you are The Counter and you enter the room when the light is on, switch it off and add 1 to your prisoner count. When the prisoner count reaches 100 - go tell the warden it's party time!

After day 100, The Counter is effectively counting the other prisoners one at a time so that he  is certain that  his tally of 100 is correct.
Before day 100 - this is an attempt to optimise the selection of The Counter as the person with the most useful information ( i.e. starting with a count greater than 1).

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 14th, 2002, 4:31am
That the modified leader solution first proposed in this thread by Salem. On 100 prisoners randomly selected it will take 9000 or so days on average. The slightly more involved methods discussed more recently will cut that to somewhere in the ballpark of 3500.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by biwema on Aug 19th, 2002, 7:50am
Hi everybody,

The leader solution seems to be quite a good approach. When we have 10 leaders, which count up to ten each, they have to visit the room at least for ten times in the first stage. The same happens at stage 2, where the master leader has to visit the living room at least 9 times.
Using [4,5,5] the situation gets a bit better, but not much. The main disadvantage of this solution is, that we have to repeat all three stages, if the first round is not successful (for example, if stage 1 is chosen too short).

My Idea is to use a binary approach with 6 stages, where the counters are not predefined, yet.
During the first stage everyone toggles the light, when he enters the room the first time. So we have finally 50 people, who counted up to 2. During the first 70 or so days, this works much faster than the case where the counters are already defined because the light is switched almost every day.

During stage 2, everyone, who turned the light off, switches the light during that stage. Everyone, who turned the light on during stage 1, does nothing.

Border effect: If after stage 1 the light is on, the first person of stage 2 turns the light of and remembers to toggle it next time the stage 1 is active. If that person has not been to the living room yet, he leaves the light on instead (that means, that he turns off the light like in stage 2, becoming a leader and switches the light on again to be counted as stage 2 member).
So, the border effects of all stages are counted by some people even if they are not counters any more.

In stage 6, chunks of 32 are combined to a piece of 64. This person, who has the 64 chunk, tries to find the remaining 32 piece by switching it off during stage 6. Besides that, he also tries to switch of a 4 chunk in stage 3. After having found both of them (the order does not matter), he declares that everyone has been to the living room.

The length of the different stages need to be defined during the meeting, we cannot do that later. I haven’t run any simulation, but I recommend a length of 300 to 400 days per stage during the first round of 6 stages.

For the following rounds, I think 100 to 200 would be appropriate. They cannot be much shorter, otherwise it is not very likely that the chunks merge. In that case the border effect carry bits just move from one person to another. If everything goes optimal, it would take 2550 days (at 350 days during round 1, 150 days after).
Unsuccessful stages add 900 days in that case.

It would be interesting to see the expectation of some simulation results when varying the stage length of round 1 around [250, 300, 350, 400, 450] and the following rounds [75, 100, 150, 200].
Is it possible to reach a value below 3000 or even 2500 days?

Any ideas?

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 19th, 2002, 11:47am

Quote:
 This person, who has the 64 chunk, tries to find the remaining 32 piece by switching it off during stage 6. Besides that, he also tries to switch of a 4 chunk in stage 3.

But how will the person know, during stage 3, that he is going to be the person who gets the 64-chunk in stage 6? He will have to get to 64 first, and then wait for the next stage 3, which defeats the object of reducing the binary method to 6 stages.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 19th, 2002, 12:05pm
Biwema, did you read this thread? I proposed the binary method you're referring to back on the 7th. As it turns out the actual optimal algorithm (as far as I know) is one where the "digit" size of the counters grows as log of the number of prisoners. That method achieves O(n* (log n)2/log log n), while binary only achieves O(n*(log n)2). For the binary algorithm it makes the most sense to have the stages grow shorter in the first round as the expected number of messages to be sent is reduced, and then have relatively short stages in all future rounds. The way you defined the stages so that you have 6 stages instead of 7 was a bit too loose. The person who gets to hold the 64 won't know he is the person who gets to hold the 64 until the final stage, which means he didn't know to pick up an extra 4 in the 3rd round. So you have to have determined by the 3rd round at the latest who will eventually pick up the 64. This means at a minimum he will have to behave differently in the 3rd,4th,5th,6th rounds and you pay a price for that in terms of the time to finish of those rounds. This is essentially using a [2,2,2,2,2,3] solution with a slight twist of the extra 4 from round 3.

As for 3000 days no I don't think its possible. Typical times for the binary method in my simulation were 4500 days. A small amount could be shaved by parameter tuning, but much less than 1500 days. The sum of expected times for success for the 7 stages of binary is 2309 days, but there is also a lot of time lost either lengthening the initial stages or going through more rounds of short stages in order to get completion.

I didn't implement a full variable digit solution but from looking at expectations and deviations I believe binary is slower than either the 3 digit [5,5,4] or 2 digit [10,10], which are both somewhere in the 3300-3800 ballpark.

Edited to add: Paul snuck in on me  :P that will teach me to be so longwinded.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 19th, 2002, 2:20pm
For reference here is the statistical data for the 7 stage binary.

Round 0   mean: 518.737752   deviation: 125.821704
Round 1   mean: 449.920534   deviation: 125.703647
Round 2   mean: 385.441972   deviation: 125.246098
Round 3   mean: 325.156233   deviation: 124.236879
Round 4   mean: 271.785714   deviation: 122.484427
Round 5   mean: 208.333333   deviation: 118.438920
Round 6   mean: 150.000000   deviation: 111.130554
sum of Means: 2309.375537   deviations: 853.062228

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by biwema on Aug 20th, 2002, 5:53am
Yes, AlexH, I have read the post from Aug 7th. Actually it gave me the idea of my variation. I agree that [4,5,5] algorithm is a bit faster because of the smaller number of stages. Nevertheless, I still prefer the binary solution because of the dynamic assignment of the counters.
If we use 25 counters who count up to 4 each (including themselves), a person can only be counted, when a counter (and they are more rare) comes to the room. Therefore that stage takes much longer (but I agree that there are fewer stages).
When we use the binary approach, a person becomes a counter if the light is on and not otherwise. So, at the beginning of the stage almost every day someone is counted.

As Paul and Alex have noticed correctly, the master counter can get the 4 chunk only in the second round because he didn’t know before, that he will become the master counter. I try to live with that.
So, we have several possibilities:
One approach is to make stage 1 and 2 a bit shorter, that it is very probable that at least 96 people are counted, but not necessarily 100 (that shifts the expected value quite a bit). In the second round these people can be collected.
The other approach is to start the second round with stage 3.

Now, Alex computed some expected stage lengths that we can tune the length of the different stages. They need to be chosen quite carefully because the penalty is 900 or more if not everyone visits the room in the first round.

Quote:
 Round 0   mean: 518.737752   deviation: 125.821704 Round 1   mean: 449.920534   deviation: 125.703647 Round 2   mean: 385.441972   deviation: 125.246098 Round 3   mean: 325.156233   deviation: 124.236879 Round 4   mean: 271.785714   deviation: 122.484427 Round 5   mean: 208.333333   deviation: 118.438920 Round 6   mean: 150.000000   deviation: 111.130554 sum of Means: 2309.375537   deviations: 853.062228

In that case I suggest these stage lengths:
Round1: [550,500,424,375,350,300] sum 2500
Round2: [150,150,150,150,150,150]

In round1/stage1&2 550 and is more than the mean and therefore quite probable that everyone is counted. If not, it is not a problem either because we need one round later, only. The remaining stages are then used to combine the 24 4-chunks to one 96. Stage 6 needs to be a little bit lucky that one counter can find the other two 32 chunks. It is like a combination of round 5 and 6 in Alex’s table. First we have to wait until 2 of the three 32 chunks enter the living room, then the second of them has to wait until the other one has been to the room as well (150 days).
In round 2 we can collect the last 4-chunk (if necessary) and announce it. If one 32 chunk is still missing, the master counter has to wait another 600 days.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 20th, 2002, 10:46am
Ok. Sorry for being a bit snippy there but I got the impression that binary stages with dynamically chosen counters was what you were calling your idea, rather than just the modification to 6 stages instead of 7.

In regards to the 6 stage idea I think you have a problem. In my estimation the best way to reduce to 6 stages would be to identify a special player in advance who is in charge of collecting the extra 4 and the 32s. The method you propose which always requires a second round is almost certainly slower than the original 7 stage method. Also your stages are going to be too short IMO, especially the 150 for later rounds.

For reference here are the formulas from my binary simulator. For the first round:

meanEstimate[i] + (.7 + .5 * sqrt(stages)) * sqrt(varianceEstimate[i])

For later rounds:

meanEstimate[stages-1] + (.5 * sqrt(stages)) * sqrt(varianceEstimate[stages-1])

the "stages-1" stage is always a 2 player round in my simulation, so thats shorthand for expected time and variance for 2 players to talk.
meanEstimate and sqrt(varianceEstimate) are the values I posted above. I'll see if I can do a test run with your numbers to compare total time.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 20th, 2002, 11:29am
I ran a test on the 7 stage version with your stage lengths (and 250 for the 7th stage in round 1). Average completion time 6877.Same random number sequence yields average completion time of 4596 using the formulae I have above.
The deviation of different trials is in the ballpark of 40 days using my curent 2000 times played per test so those numbers aren't exact but they are close.

Those formluae in my program are derived from the proof I gave earlier on why binary stages is O(n (log n)2). The constants .7 and .5 are arbitrary but gave reasonable results on some test cases, with each new round winning somewhere between 2/3 and 3/4 of the still active games.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by James Fingas on Aug 26th, 2002, 1:59pm
I found biwema's proposal interesting, and so I have done some analysis using a spreadsheet. From my calculations, the suggested stage lengths are too short, and the optimal expected time is about 5500 days.

The nice thing about the binary solution is that we don't have to pick anybody ahead of time. Consider the first round: the first time a person visits, they will drop off their counter if the light is off, or pick up someone else's if the light is on. The first stage can be over as soon as everyone has visited! This thought encouraged me to try and figure out when everyone will likely have visited the room.

At first, I tried to find a formula, but I guess I'm not as good at probability as I once was, because I couldn't find one that seemed consistent. So I made a simulation spreadsheet. This is probably better anyways, since I'm not sure how to differentiate factorials  ;)

It turns out that the probability that everyone has visited gets up to 50% when you get to 498 days, and that after 680 days you are up to 90%. This got me thinking: what is the best value for this probability? Should we quit early to make short stages, or should we keep going to reduce the probability of round 1 failing.

Of course, the best value is achieved when adding one extra day to a stage reduces the probability of round 1 failure enough so that we can take one day off the expected incarceration time (I used the word incarceration  8)). After this, you get only marginal improvements in round 1 success rates by adding extra days, and you're better off taking your chances that you'll need a second round. Before this, you can significantly improve your chances in round 1, avoiding the penalty of 7 extra rounds.

After calculating this all out, I got the following stage lengths:

stage 1 : 1006
stage 2 : 995
stage 3 : 933
stage 4 : 849
stage 5 : 781
stage 6 : 713

stage 7 success : ~100
total success : 5377

stage 7 failure : 643
round 1 total (failure) : 5920
round 2 : 643 * 6 + ~100 = 3958
total (failure) : 9878

The probability of not getting out after the first round is about 0.2% per stage, for a grand total of about 1.5%. This
gives another 81 days expectation for the second round. The total expectation is therefore close to 5450 days.

This makes good logical sense too: because of the extreme price the prisoners must pay for not making the first round, it's better to wait longer in the first round just to make completely sure. The second round can be played with each stage lasting 643 days to speed things up, since chances are you only have one person left to collect at any stage in the second round.

The way I dealt with the extra 32 and the extra 4 was to initially assign 28 people 2 counters instead of 1. This way, there are only 72 people who must be counted in stage 1, and then 64 people who must be counted in stage 2, 32 in stage 3, etc.

The problem with the binary solution is that it has so many stages. Each stage eliminates whatever memory the system had, and so you have to wait a long time to be sure of anything.

The interesting thing that I find about this is how the stages in which you have fewer people to collect go faster than the stages in which you have more people to collect. In either case, the stage can be over only when everybody visits (before then, somebody you need to collect might not have visited yet).

All right, now it's time to consider the solutions where each person is assigned a day... :)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 26th, 2002, 5:50pm
Just for the record ...

on 08/07/02 at 19:19:56, AlexH wrote:
 Random additional tweak to the n (log n)^2 method. If we're doing this in binary,  we don't actually have to designate who are drones and who are counters in advance. Everyone starts as active. If an active person enters the room, they toggle the light switch. If it was initially on they call themselves a counter and stay active in the next stage (though they do nothing further during this stage). If it was initally off they call themselves drones and then become inactive from that point on. Of course anyone, whether active or not, has to do the turn off and account for it next time through if the light is on at the end of the stage. This doesn't change anything asymptotically, but it saves a factor of 2 in expectation.

James:
I wrote a program to perform the binary dynamic method with 7 stages on 100 prisoners. The trick with finding the optimal time is that you're optimizing over all stage lengths simultaneously (including those in later rounds) and there will be local extrema that are not the global extrema. My numbers are certainly not perfectly optimal, but they were derived from the properties of the distribution and should be at least close. The couple lines of code (for determining stage boundaries) I posted above yield close to 4500 days as the expected incarceration time under the dynamic binary method with 100 prisoners. The chance of success in each round with these numbers is in the ballpark of 2/3-3/4. In batches of 2000 trials generally the worst case takes about 5 rounds to complete.

I think its slightly faster to get to 128 by just starting 1 players counter at 29 and all the others at 1, though the difference is very small.

Here is the c++ code for determing the expected mean/variation of each stage's completion time.

// Set up data used for determining stage sizes
// slightly inefficient computation method

meanEstimate = new double[stages];
varianceEstimate = new double[stages];

k=numPrisoners; // k is anticipated number of message passers in current stage
for(i=0 ; i<stages ; i++){
varianceEstimate[i] = 0.0;
meanEstimate[i] = 0.0;
for(j=1;j<=k;j++){
meanEstimate[i] += // computing H(k) here
1.0 / (double) j;
varianceEstimate[i] += // summing variances of geometric variables
(double) (numPrisoners - j) * (double) numPrisoners / (double) (j * j);
}
meanEstimate[i] *= numPrisoners;  // mean =  Harmonic(k) * numPrisoners
k = (int) ceil((double) k / 4.0) * 2;
}

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by James Fingas on Aug 27th, 2002, 8:06am
Alex,

I found a couple bugs in my spreadsheet. I had overpenalized the first-round-failure case, leading the longer-than-necessary stages. Now my stage lengths are:

stage 1 : 755
stage 1 : 742
stage 1 : 674
stage 1 : 605
stage 1 : 536
stage 1 : 470
stage 7 success : average 151
round 1 success : average 3933
round 1 success probability : 0.774

stage failure probability : 0.964 (they're all the same!)
stage 7 failure : 402
all stages in round 2 : 402

each round failed : 2814

net expectation: 4500 days (roughly)

Now this is similar to what you are suggesting. Maybe our solutions are not so different after all...

I guess I should check my work more carefully the first time!

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by biwema on Aug 27th, 2002, 8:18am
Hi,

James and AlexH, that are good ideas do merge the 4-chunk. Nevertheless it is time I gave up the approach with the binary stages :(. However much they will bring down the average running time of each stage, the number of stages is still a big disadvantge.

Besides the [2,2,2,2,2,3] approach I also simulated a new [3,3,2d,2d,3d] approach where 3 stages are dynamic. Here only 28 of the 36 assigned counters have to count up to 3, the remaining 8 only up to 2 in stage 1.

In my simulations I simulated all the stages separately, that they achieve an overall success of about 70% after round 1. That means, that a 6 stage approach must have 95% in every stage, a 2 stage approach only 85%.

[3,3,2d,2d,3d] gains 4100 days, If I replace the [2d,2d] part by a [4] it gets a bit worse.

[5,5,4], [5,4,5] and [4,5,5] reach 3700 days each; maybe [5,5,4] is slightly better than the other (between 71.5 and 72%).

Surprisingly, [10,10] reaches with an 2200 and 1500 stage also 3700 days at 71.5%. If the first round is unsuccessful, a second round will a fewer days due to the smaller number of stages, and therefore increase the global expected value by a smaller amount. Maybe this approach will ahve the smallest global expeced value.

In the riddle itself, William Wu says:

Quote:
 Note: OK, so you have a solution. Big deal. Now prove it's optimal! And e-mail me the proof please! =)

Now, several solutions are so close and depend much on fine tuning. I think a proof of a solution being optimal could be quite difficult. I wonder which solution William had in mind when he added that part of the question.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Paul Hammond on Aug 27th, 2002, 8:47am
FWIW, with Alex's 7-stage binary method and the stage lengths below, I get a mean release time of ca. 3500 days:

-First round-
Stage 0: 600
Stage 1: 500
Stage 2: 450
Stage 3: 400
Stage 4: 375
Stage 5: 350
Stage 6: 250

In subsequent rounds, all stages are 200 days long.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 27th, 2002, 9:13am
James: yep those look pretty close to my stages.
774
705
639
577
520
448
375
All stages in future rounds: 298

Technically my stages are all 1 day longer in some sense, since you can steal 1 extra day per stage by having the last day of 1 stage also be the first day of the next. My stage lengths aren't actually tuned to the 100 case, they are derived from the formulae I posted above which work for any number of prisoners. We differ a little more early on I think because I use 1 prisoner with a 29 counter instead of 28 with counters at 2.

biwema: if we restrict ourselves to these staged counter methods then selecting digit size O(log n) appears to be optimal asymptotically as I discussed earlier. O() notation hides constants of course so this doesn't prove anything with a fixed size problem.

I'd be very impressed with any formal proof of optimality over all possible solutions especially on the specific 100 prisoner case. It seems like it would be very difficult even given that you know the optimal algorithm.

Edited to add: Paul snuck in on me again  :P
Wow. That result is faster than I would have expected for the binary method. I will have to take a look at it.

Edited again: I plugged those stage lengths in and I wind up with averages around 5900. I think you might have an error in your formulae somewhere.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Penumbra on Aug 28th, 2002, 9:03am
First off - nice long thread that actually homes in on the exact mathematical deterministic solution.. so congrats for all your dedication (nay... obsession!!)  ::)

FWIW.. All the mathematical approaches so far are based in some way on the light's binary "on/off" state as the only information that can legitimately be passed on to the next occupant of the lounge.
However.. there is a third "flag".. the silence of the previous person(s).  When you enter the room, you know that the person before you failed to shout out "Release us!".. so they knew that that not everyone had entered the room.  This silence could be used in some way as a decision maker...
Unfortunately I'm not sure how...!!!

One other comment.. I do like the "hold the meeting in the lounge" solution.. it was what I came up with when someone sent me the puzzle via email.. (and which led to my journey here in search of the solution!!)  HOWEVER... It should be pointed out that the later puzzle in the list "100 Prisoners and 2 light switches" specifically states that "the prisoners meet in the CAFETERIA to agree a plan"...
I guess that's there to rule out the "trick question" solution.  Happy hunting & don't give up......    :)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Aug 28th, 2002, 2:52pm
I'm not sure what you're talking about with regard to people failing to shout out "release us". As soon as someone says that you either 1) get released and know that everyone has been to the lounge (not that you care anymore) or 2) get executed and know that not everyone has been to the lounge (once again, not that you care).

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by isu_cyclones on Sep 1st, 2002, 12:54am
Hi guys,
This might be a solution.

In the meeting, one of them is assigned as the leader.

Only the leader can switch the bulb off.
Everyother person should switch on the bulb exactly once.
This should be done the 1st time they find the bulb off.

Note that this necessarily need not happen in their first visit, as in the case when they find that the bulb was already on.

The leader keeps a count of the number of times he turns on the bulb and when it reaches 99, he announces.

===============================
In a world without doors or walls,
who cares for Windows or Gates.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by isu_cyclones on Sep 1st, 2002, 1:01am
Oops... the last line shld read as,

"The leader keeps a count of the number of times he turns OFF (not on) the bulb and when it reaches 99, he announces."

===============================
In a world without doors or walls,
who cares for Windows or Gates.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Sep 1st, 2002, 1:39pm
Hi isu, welcome to the board. What you posted is a correct solution which we've dubbed the "single leader" model. A while back Paul had a really nice idea for doing things faster and lately we've been talking about where that idea takes us. The single leader model takes up over 10,000 days on average, and generally grows like m2 for m prisoners to finish, while these alternatives give times in the 3,500-4,500 range and grow like m(log m)2/(log log m) or m (log m)2

Title: not giving up on binary
Post by pa0pa0 on Sep 7th, 2002, 8:31am
Has anyone tried combining Salem's modification with the binary method?

(It doesn't seem feasible to combine it with the non-binary methods, since then the assistant counters can get stuck while incomplete.  But with the binary method, there are no incomplete counters.)

Thus: first 100 days as per Salem, after which either the light is still off (leading to victory on day 101) or it is on and the binary method starts at that point (with the polarity of the bulb reversed).  The leader is pre-determined during the prelude, and gets an initial count of (on average) about 12, but the assistant counters are determined dynamically.  The leader never releases any counts, but only sucks them up.

It would be nice if this brings the binary method back into contention.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by AlexH on Sep 7th, 2002, 10:58am
Thats a good point, we could combine that idea with the binary dynamic idea, but there would be 2 problems.
1) We'd have to pick a window much smaller than 100 days to be optimum-- I talked about this a while back but its even more the case if we're trying to apply it to the dynamic methods.
2) Our gain will be very small. Let k be the number of visits before the first repeat. If k is much smaller than m (which it almost always will be since k averages O(sqrt(m)), then I'd estimate we'd gain about k*((log2k)-2) days. For m=100 if we spent 16 days on this stage (which I think is our optimal) then I estimate we'd have a net gain of about 17.3 days in expected completion times of the stages, but we'd get less benefit on the whole since this trick increases the variance of stage finishing times.

Intuitively the problem is that while this trick does gain us a small reduction in the number of active participants in the next few stages, those small reductions are of very small benefit because the stages take time proportional to m * log (# active) instead of m * (# active) as it was in single leader case.

It a good point and you're right it does work, but the gains are unfortunately very small.

Edited:
I still agree with everything I said about the asymptotics, but the hard numbers were actually computed as if it were the 128 prisoner case rather than 100. On 100 you'd gain a bit more because you'd have a good chance passing the 96 threshold and saving some combines in the 5th stage. This still won't be close to catching the larger digit versions but it will be a bit better than just 17 days.

Title: 100 prisoners & Light bulb solution
Post by wviljoen on Sep 16th, 2002, 1:40am
The essence of this problem lies in one word - Random! First of all it says explicitly that no one can see the light from their cells and second the warden will not have them meet in the common living room because then he needs to be shot for stupidity. Random is the key. If he means that he will select a person each day randomly then I assume he means he will go through the list like a the Random function on a CD player. It will play the whole playlist but in no particular order. This is simple, everyone that goes into the room leave the light off until such a time that a person goes in for the second time. He turns the light on and the next person that sees the light will make the claim. Therefore on the 102nd day they will have their freedom. However, if Random meant that the warden can select any person more than once without having another person selected at all, this is closer to true random - pretty much like the lotto draw and then there's no luck for the prisoners. In this scenario they are stuck and no binary and no statistics will save them because there is no solution.

Regards
Qpin

Title: Re: 100 prisoners & Light bulb solution
Post by S. Owen on Sep 16th, 2002, 7:36am

on 09/16/02 at 01:40:19, wviljoen wrote:
 If he means that he will select a person each day randomly then I assume he means he will go through the list like a the Random function on a CD player. It will play the whole playlist but in no particular order. ... However, if Random meant that the warden can select any person more than once without having another person selected at all, this is closer to true random - pretty much like the lotto draw and then there's no luck for the prisoners. In this scenario they are stuck and no binary and no statistics will save them because there is no solution.

Yeah, the intended meaning is your "true random" interpretation, or else it's too easy. But even with truly random choices they can achieve their freedom with 100% certainty... see the last, oh, 100 posts or so!

Title: Applications of 100 prisoners & lightbulb problem?
Post by S. Owen on Sep 16th, 2002, 7:39am
The analysis of this problem has gotten quite sophisticated here, far beyond the call of duty. I have to wonder: is this a disguised version of a "real life" problem? I suspect that it is related to Byzantine agreement problems in randomized algorithms, but haven't thought it through.

I'll see what I can come up with, but it would be nifty if this was all just relevant enough to produce a respectable paper on a known problem. Any ideas?

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Alex Hartlaub on Sep 17th, 2002, 8:32am
Can we get a actual answer from w.wu?  ::)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Oct 14th, 2002, 8:42pm

on 09/17/02 at 08:32:28, Alex Hartlaub wrote:
 Can we get a actual answer from w.wu?  ::)

I don't have the actual answer apparently! :o Prior to all the arguments in this terrific thread, the best answer I knew of was the leader solution combined with Salem's modification. I asked my algos professor last semester if this was optimal, but we couldn't figure out how to prove or disprove its optimality. I never thought of a stage-based algorithm, which apparently beats the leader solution by a mile.

Following the same curiosity that S.Owen voiced, I'm trying to find out if this problem has already been studied extensively in the academic world, but perhaps under a different guise. Just got a book from the library about distributed algorithms -- algorithms for systems where there are multiple agents working toward some common goal. It would be most exciting if the world doesn't know about the stage based solution yet.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Oct 18th, 2002, 4:53am
Asked some more professors but they couldn't think of anything offhand, or are too busy doing far less interesting things to think about it. Perhaps it would be easier to find existing material on this riddle if we take a reverse-engineering approach and ask ourselves what real-world problems this riddle models. What kind of problem would require:

1. A 100% probability of success. (Many lives on the line?)
2. Multiple agents working toward a common goal.
3. Agents randomly take turns using a shared resource (the light bulb)

I can't think of many situations that require the first requisite ... in the real world I think we usually accept that a system can fail with some tiny probability. Then again, I've never been in the real world so I don't really know. Perhaps a good variant of this problem would be to design a slick algorithm that gets the prisoners out in a short time, given that we can tolerate a .99 probability of success (or some other high value close to 1). If we sacrifice a sliver of certainty, could we get the prisoners out in a thousand days or so? A solution to this variant might be also more practical for analogous real-world situations.

Let's say hypothetically that we find the optimal solution to the 100 prisoners problem or its variant. How do we prove that it's optimal? We could get an optimal solution and not even know that it's optimal.

OK, I really should sleep now.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by thelonious on Oct 23rd, 2002, 8:40pm
I think we are making some assumptions here.  And that's fine.  We should be sure and keep those in mind however.  It appears from the solutions here that we are assuming an even distribution random selection.  For which, there is probably a better term than what I just used.  But we seem to be saying, that, given a certain percent chance that the random selection process will have all prisoners selected at least once by a certain number of days, we proceed from there.  For example, in the solutions that work around 3500 days with this type of random selection, how do they perform when prisoner #1 is only selected to enter the living room on day 5000?  And only every 5000 days?  This is not probable given a decent random selection process, but if we assume a good random selection process, say, after 2000 days we know that all prisoners will have visited the room at least once, then we can say, after 2000 days someone can just make the assertion.
If we assume a random set where one single prisoner is never selected, then that's obviously ridiculous.  The riddle loses all meaning as the satisfying condition is never met.  But if we are assuming an even spread random selection algorithm, for which there is probably a better term than what I juse used, then we are guaranteeing that all prisoners would have been selected in X number of days.  So if we make this assumption, the optimal solution is back to someone making the assertion on day X.
So it seems that we are working on the assumption of a level density weighted random selection process, for which there is probably a better term that what I just used, and working from there to decide on stages that would most likely be successfully completed in a certain amount of time.  Which seems just a variant on assuming that all prisoners would have visited by day X.
So I think we are Schroedinger's cat chasing our own tail.  But it sure is fun.
Just thought I would throw in a few thoughts.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Oct 23rd, 2002, 10:49pm
I think it's implicit that the random selection is uniformly distributed amongst the 100 prisoners, since no special distribution was specified. Regardless, I have modified the problem slightly so it says that the warden chooses a prisoner equally at random each day. (Choosing with replacement is also implicit since the chosen prisoners return to their cells afterwards.)

(regarding the wording you were looking for, here are some choices: uniform distribution, uniform probability mass function, equally at random, equiprobable, uniformly at random = u.a.r.)

(another good, common "term" is i.i.d. = independent and identically distributed. used to describe random variables.)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Josh Johnson on Oct 25th, 2002, 2:17pm
Okay, here is my contribution to the 'single leader' approach.  I read through all the posts and I don't think I've seen this up here anywhere yet.  The difficulty with this problem, as noted by several of you already, is the randomness used in selecting who goes into the room with the light.

The fastest way I can calculate the leader approach to work is if the leader is randomly selected every other day starting with the second day and the other 99 inmates are randomly selected to go (without repetition) every other day starting on the first day.  Keep in mind, the probability of this happening is almost zero, but not actually zero.  In other words, improbable but not impossible. The leader is only allowed to turn off the light and the inmates are only allowed to turn on the light.  Thus the following would occur (L=leader, Pn=Prisoner n):

P1,L,P2,L,P3,L....P99,L

If this is the case then the prisoners can be released in 198 days (when the leader turns off the light for the 99th time).

The second thing I wanted to post was my MATLAB script (minus comments to save space) to determine the effectiveness of the leader approach.  I have run this script about 5,000 times and found the minimum number of days to be 6,324.  This number, however, is based on the randomness of selecting which inmate enters the room and is definitely not the correct answer.  Comments are welcome (except on the coding style/efficiency; I'm an aerospace engineer, not a seasoned computer programmer).

clear all;
for n=1:1000
NumPrisoners = 100;
Prisoner = zeros(NumPrisoners,1);
Day = 1;
LightStatus = 0;
Chance = 0;
while Chance == 0
PrisonerSelected = fix(NumPrisoners*(rand(1)-.001))+1;
if PrisonerSelected == 1 & LightStatus == 1
LightStatus = 0;
if LeaderCount == (NumPrisoners - 1)
Chance = 1;
end
elseif PrisonerSelected ~= 1 & LightStatus == 0
if Prisoner(PrisonerSelected) == 0
LightStatus = 1;
Prisoner(PrisonerSelected) = 1;
end
end
Day = Day +1;
end
Results(n)= Day;
end
min(Results)

Each run of this code does 1000 iterations of the puzzle.

-Josh

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by SWF on Oct 28th, 2002, 9:52pm
Unless Paul Hammond's calculation of the 7 stage binary method involves some tricks not documented here, I think the calculation giving 3500 days is incorrect.  Previously, both AlexH and J. Fingas estimated the 7 stage binary takes about 4500 days.  With some further optimization of the stages, I come up with around 4250 days for this method.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by SWF on Oct 28th, 2002, 9:59pm
The method with the lowest mean number of days that I have found is 3536 days.  The technique is similar to the 2 stage methods discussed earlier, and the duration falls in the range estimated by AlexH.  I implemented a simulation of the details to accurately estimate the number of days.  This value for the mean number of days was obtained after simulation of over a million cases, and should be accurate to within a day.

Stage 0 involves defining who is responsible for counting.  One prisoner becomes the primary counter, and is given the task of collecting a certain number of counts, the primary count, in stage 1.  The secondary counters are responsible for collecting a number of counts in stage 1 that is not necessarily the same as the primary count.  In stage 2 the primary counter collects signals from the secondary counters who have succeeded in stage 1.  Stages 1 and 2 are repeated until the primary counter's count reaches 100.

Two different approaches both give 3536 days:  a primary count of 12, and eight secondary counters who count to 11; or a primary count of 10 with ten secondary counters who each count to 9.  Using a primary count of 10 and nine secondary counters who each count to 10 is only slightly worse.  The method of determining who is a counter in Stage 0, typically gives the primary counter one extra count over the rest and takes advantage of having the primary count be one greater than the secondary count.  Establishing counters in Stage 0 saves only about 70 days over starting with pre-established counters, but the problem is to find the minimum, so every day saved counts.  I think there is still some room for improvement.

There are a few tricky details in such things as dealing with cases when somebody is reponsible for acting as a counter twice, and ways of reducing the chances of this happening, especially in Stage 0.  I can go into the details if anybody is interested.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by thelonious on Oct 29th, 2002, 8:46pm
Thanks for the info, william wu.  The point I was making it that if we can assume an i.i.d. selection set, then the optimal solution would be to wait the number of days required for it to be guaranteed that everyone was selected once.  If the case can be made that that guarantee can never be reached probability wise, then wouldn't that indicate that we didn't have a proper i.i.d.?  If we do have a valid i.i.d. set, then don't the chances that there are any prisoners not selected yet have to become 0% well before 3000 days?  Knowing that we have an i.i.d. set in a way puts a bias on our expected randomness.  Or do it?  I'm thinking along the lines of that somewhere in the definition of i.i.d. the case for non-selection after a certain number of selections is ruled out.  But I know not.
If you can derrive this conclusion from the definition of an i.i.d. set, then any other solution becomes less than optimal.  But I suppose a possible set could be constructed that causes the other solutions to work optimally.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Oct 29th, 2002, 9:27pm
I'm not sure what you're trying to say. Firstly I think you mean u.a.r; in my previous post I just threw in i.i.d. as another common term that's good to know, but u.a.r doesn't mean the same thing as i.i.d.. Sorry that was probably confusing on my part. Uniformly At Random means that everytime the warden chooses an integer between 1 and 100 using his calculator's random number generator, each of those integers is equally likely to be picked. So the probability of picking any particular number is 1/100. These numbers are chosen with replacement, so if the number "13" is picked in the first iteration with probability 1/100, then in the second iteration, the probability of picking "13" is still 1/100. There is never a "guarantee" that everyone will be selected after so many days have passed. There is always a small yet nonzero probability that the warden's random number generator always misses some of the integers ranging from 1 to 100. So you can't just wait a certain amount of time and then make the assertion (although perhaps that's the simple algorithm most prisoners would come up with, unless they had a hacker or mad scientist in their bunch, or maybe someone from this forum  :o ). However, the light bulb gives us hope, because we can use it to record visits to the room, and eventually truly prove to ourselves that everyone has been in the central living room at some time. When we say that such and such algorithm being currently disputed takes about 3500 days before completion, that's an average running time; we can't get an exact running time because of the random prisoner choosing. An algorithm with average running time of 3500 days could still consumes 5,000,000 days for a particularly bad case.

Apologies if I misunderstood your post.

SWF: yes, we are interested  :)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by SWF on Nov 1st, 2002, 6:36am
Here is more information on the method which gives a mean release time of 3535.6 days (based on simulating 11 million cases).  Standard deviation is around 607 days, and median is 3370 days.

First the basic version will described, which takes an average of 3600 days and may not be much different from previous discussions here.  A prisoner is designated the primary counter, and 8 other prisoners are designated as secondary counters.  At the beginning everyone has a count of 1, call this countA.  There is also a value assigned to each person for number of times this person is responsible for getting his count to 11 and signaling in stage 2, call this countB.  The 8 secondary counters start with countB equal to 1, while everyone else, including the primary counter start with countB of 0.  The primary counter also has the responsibility to collect 12 individual counts.  The primary counter tracks an additional count, countC, which is number of individual counts collected.  Primary counter needs this to distinguish from the counts collected in groups of 11 in Stage 2.  The number of individual counts each person, except the primary counter, is required to collect is 11 times his value for countB, while the primary counter needs to collect 12 + 11*countB.  Each prisoner has his own value for countA and countB, so maybe I should subscript them like countAi.

The first time through, Stage 1 is 2252 days long. If somebody is called in during this stage and the light is off, anybody whose value for countA (except for primary counter who compares countC) is greater than the number of individual counts he is assigned to collect must turn the light on and subtract 1 from his value for countA (and also from countC if this person is the primary counter).  If somebody is called into the room in Stage 1 and the light is on, if his value for countA (countC for primary counter) is lower than the number of individual counts he is required to collect, he turns the light off and increases his value for countA by 1.  When the primary counter collects an individual count in Stage 1, he also must increase his value for countC, and claims it is over if his value for countA is 100 (but that is extremely unlikely to occur the first time through Stage 1).

The first time through, Stage 2 is 1610 days long.  If the light is on the first day of this stage, the prisoner called in that day must increase his count (as in Stage 1) by 1 and shut the light off, even if he has already collected his share of individual counts.  The prisoner called the first day of stage 2 then behaves as if the light were off when he entered the room.  When the light is off anyone other than the primary counter with countA >= 11 and countB >= 1 must turn the light on, subtract 11 from his value for countA and 1 from his value for countB.  If the primary counter enters and the light is on, he increases his value of countA by 11, turns the bulb off and calls the guard if his value for countA equals 100.

Repeat Stages 1 and 2 with lengths of 302 and 358 days respectively until the primary counter collects 100 counts.  Also, on the later passes through Stage 1, on the first day of the stage, if the light is on whoever is called that day increases his value of countA by 11.  If that person is not the primary counter, he must also increase his value for countB by 1.  Thus, he has picked up the responsibility to signal in Stage 2 from one of the former secondary counters, and somebody could become responsible for signalling more than once in Stage 2.

The above is for the primary and secondary counters named in advance, but an improvement of about 65 days can be obtained by establishing them in a Stage 0.  By doing this the primary counter will typically start with a countA of 3, and secondary counters with countA=2.  This improves over the basic method where they start with countA=1, but it runs the risk of having some prisoners have to count to 11 more than once (countB>1).  This is running long, so I will give the details of Stage 0 some other time.

Due to the complexity of explaining this method just the prisoner organization meeting at the beginning could take 3536 days.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by -Tom-1 on Nov 7th, 2002, 2:53am
ok well if u ignore everything at the top and read the last lines it says one night they meet somewhere, so where can 100 people meet? well of corse in the centeral living room so then all of them have been there - simple

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Nov 7th, 2002, 6:10am
Alright, now they have to meet in the courtyard. Heh.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by -Tom-1 on Nov 7th, 2002, 6:41am
ok well i say thats answer

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by bound_master on Nov 9th, 2002, 12:22am
Assuming hard obstacles to pass, such as

-the prisoners in the cells can't see the flickering light
-only one meeting occurs before the actually visitations to the living room.

I think the fastest way out of there (using the light bulb) would be:

-Break the light bulb into 99 pieces, whoever is the first one there...then whenever someone new enters the room for the first time, he/she takes a piece of broken glass, until none is left.   ;)

Without using the light bulb:

-leave some kind of mark behind, such as Roman numeral markings on the wall (1-100, each representing a prisoner), or a piece of clothing if your visiting for the first time, or dismembered fingers, or even fingernails.  Once 100 markings or items are left behind, then you know 100 have been there.

Of course this only works if the janitor doens't come by to clean the room.  In that case, an assasination attempt can be done on the janitor with a sharp tooth shot through an empty cylinder (pen) that hits him in the neck and kills him instantly!

See how simply and quickly it can be done.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by towr on Nov 10th, 2002, 7:54am
you could also unscrew the lightbulb, and then screw it back in 99 degrees, each next (new) prisoner unscrews 1 degree, when it falls everyones been there..
But prisons are notoriously paranoid abotu people getting to the lightbulbs, sinc ethey might kill themselves with the glass (or attack the guards)..
So it's not really an option after all..

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by SWF on Nov 11th, 2002, 7:53pm
Here is the detail on Stage 0 that I mentioned would be forthcoming in my Nov 1, 2002 post.  This defines the way the primary and secondary counters are established in the first 21 days.  This may be somewhat boring, but is given to document the most efficient method so far.  Everyone starts with countA set to 1 and countB to zero (see my earlier post for definitions).

In this stage I tried to reduce chance of somebody picking up double responsiblity for secondary counting (countB<2), but it can still happen.  Also tried to assign counting duties in a way which gives the counters a head start by collecting individual counts from others.  There is probably room for improvement here.

Day 1: This prisoner subtracts 1 from his value for countA.

Day 2: If this prisoner did not enter in Day 1, subtract 1 from countA and turn light on, otherwise leave light off.

Day 3: This prisoner is designated the primary counter.  If light is on, turn it off, and if countA is 1, set it to 3 otherwise set it to 2.  If the light was off when entering the room add one to countA (i.e. same prisoner was called all three days and countA becomes 1 again).  Most likely countA for the primary counter will be 3 which is a pretty good start in collecting 12 individual counts.

The next pair of days is repeated for i=0 through 7:

Day 3+2*i+1: If light is on, turn it off, add 1 to countB (i.e. become a secondary counter).  If light was off when entering, keep light off if countA is 0, otherwise subtract 1 from countA and turn light on.

Day 3+2*i+2:  This day try to make assign a secondary counter, but postpone the responsiblity to next prisoner if today's prisoner is already a primary or secondary counter.  If today's prisoner is already a primary or secondary counter then turn light on, and if light was already on add 1 to countA.  If today's visitor is not a primary or secondary counter add one to countB (become a secondary counter), add 1 to countA if light is on, and turn light off.

Day 20: If light is on and today's prisoner is not a primary or secondary counter then add 1 to countB and turn light off.

Day 21: If light is on add 1 to countB, turn light off.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by luke's new shoes on Nov 12th, 2002, 3:27pm
is it possible there is more than one switch that controls the light?
if so, the on off possitions of the switches can be used to convey data to the other prisoners.

Title: A variation of the problem
Post by Changer on Dec 6th, 2002, 12:22pm
This question is a variation of one that I had read before with 23 prisoners and 2 switches.  I found a link to one retelling of it on the IBM website, http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/challenges/
(choose July 2002)
On the original website where I had read this, some mathematics professor had offered up a proof of the solution which I can't remember but seemed correct.  The solution given on the IBM website was essentially the counter method.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Devarajan on Dec 22nd, 2002, 5:33pm
Hi all,
I have a simplest soln. for this problem..but i dont know whether that is the efficient way but i know this is perfectly right..here you go..
During the meeting,one person(calling him coordinator or counterer) decides that he will always switch of the light whenever he goes to the room and also start counting the no. of times he switched off.Every other person will switch on the light once and does nothing every other time..On the 100th time the co-ordinator switches off will be sure everybody reached this cell atleast once..
Hey guys, let me know if this soln. is convincing to you all..
Thanks,
Deva ::)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by SPAZ on Dec 31st, 2002, 10:50pm
one other solution is just when your in the room yell allowed and say" has anyone not been in yet?" once someone does this and no reply is given then your free...

all solutions with wait this many days and so forth are not 100% because it is possable that if random one person will never be picked for going in the room

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Dec 31st, 2002, 11:25pm
Deva: That solution works but is suboptimal. It's a long thread, but if you read it from the beginning you'll see a discussion of it from a few months back. Now we're studying solutions that use multiple counters who merge their data over time.

SPAZ: I guess I'll have to add that the cells are soundproof.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Snyder8 on Jan 7th, 2003, 12:54pm
Ok, I'm not even going to attempt this riddle, instead I'll take a different route. I think I found out where the riddle came from, http://baranduin.us/fics/blissfulnights10.html . It appears to have originated in a Lord of The Rings book although I'm not 100% positive. I read the section with the riddle and Frodo never seems to figure it out, which leads me to believe that there is no answer and we are all wasting our time.  I'm not sure if he could have wrote something that wasn't his original idea and without an answer provided in the book I think I'm going to steer clear of this riddle.  I havent spent that much time researching the origin, so there's a good chance I may be wrong, just don't hold me to this.  If anybody else finds anything about the origins of the riddle  it might be helpful to solving the problem.  Until then we might be searching for something that doesnt exist... If I find anything else I'll post it here... don't lose any sleep over this one, I'm skeptical of an answer... you should be too

But on a side note... this problem uses a candle instead of a lightbulb, which eliminates the switch.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Jan 7th, 2003, 1:51pm
Hahaha  :D  So you were serious in that e-mail! I'm pretty sure it didn't come from LOTR. The author of the fanfiction phrases the riddle the way I did. I'm responsible for making up the storyline that says prisoners will be killed explicitly for their stupidity, and also introducing the MENSA aspect of story which is not present in the LOTR context. The puzzle might have originally come from Hungary, since apparently it was making the rounds of Hungarian mathematician parties last year according to an IBM research site.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Felipe de Toro on Jan 13th, 2003, 5:50pm
(Sorry, my english is awfull. I'm from Chile).

The solution is very simple.

First think that there are only 5 prisoners (for simplyfication).

1 2 3 4 5

Prisoner number 4 (for example) will count the first visit of each other prisoner to the room of the light bulb.

If a prisoner (not number 4) goes to the light room and it is his first time and the light is OFF, he must turn it ON. This was his first time.

If a prisoner (not number 4) goes to the light room and it is his first time and the light is ON, he must leave it ON. In this case, he consider that this is NOT his first time. He will wait for another chance (with the light turned OFF).

If a prisoner (not number 4) goes to the room and it is not his first time, he must leave the light just as he found it.

If prisoner number 4 goes to the room, he look at the light. If it is ON, it means that another "new" prisoner (prisoner in first time) went to the room. If it is OFF, it means than from his last visit to the room, no other "new" prisoner went. If the light is ON he MUST turn it OFF, then another "new" prisoner can turn it ON. He is the only one that can turn OFF the light.
He count every "new" prisoner (when the light is ON) and when he find that the number is 4 (plus him=5), then he knows that every prisoner went to the light bulb room.

You can apply it for 10, 20 and even 100 prisoners.

Bye!

Felipe de Toro.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Felipe_de_Toro on Jan 13th, 2003, 6:47pm
Sorry, I'm very embarassed. My little brother, Juan Pablo, told me that this problem was unsolved here (he must learn a little of english), and I didnt read all the messages in the forum before I sent my solution. I just posted in the forum he wanted. Nevertheless I will keep looking for a better solution.

Thanks.

:-[

Felipe de Toro

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by rilgin on Jan 19th, 2003, 12:55am
I do not have the mathematical or statistical skills to evaluate the following method which is similar to the other ideas posed but may add additional efficiencies.  It has some intuitive possiblities.

My wrinkle is a method to dynamically identify "counters" during a first state and increase the chances that everyone is counted during that period.  I have used the first 100 days but math might specify a different period.  My thoughts are not complete but I wanted to see what people here thought.

You divide the 100 days into the first 4 days then into groups of 3.  In each grouping other than the first 4 days, the "second" prisoner will be the counter or he will pass the count to the "third" prisoner in the group as follows.  The first four days are similar to the rest but you can save a day of efficiency with the counter being the "third" or "fourth" day.

Day One:  Turns light on.

Day Two:  If not the same as Day One, Prisoner toggles the Room light off.

Day Three (1st potential Counter):  If the room light is
off, and Day Three is a new prisoner, he keeps room light off (this just tells Day 4 that the first three days were all new prisoners and that day 4 will be the counter).  If there has been one or more duplicate prisoners, Day Three tells Day 4 that Day Three is the counter by turning light on.

Day 4 (2nd potential counter):  Is told by Day Three if Day Three wants him to count (light off) OR that Day Three is keeping the count (light on).  If Day 4 Is the counter, he knows that so far the count is 3.  He then counts himself and leaves the light off for Day 5.   If the Day 4 prisoner is not the counter but has been previously in the room (i.e. already counted), he also leaves the light off.  On the other hand, if Day 4 is not the counter and has not been in the room (i.e. not counted yet), he leaves the light on for the first prisoner in the next group.  This will pass responsiblity for future reporting to that prisoner.

**********  Next Groups are in Threes **********

First Day:  If light is off, he ignores previous grouping (no responsibility has been passed to him).  If light is on, he knows that previous Day Prisoner was both new to Room AND needs to be counted.   In other words, he has been passed a count of 1 to utilize now or to pass on later in another stage.  He then reports to Second Day by leaving the light on to pass 1 or off to pass 0.

Day Two:  If Light is on AND Day Two Prisoner is new, he leaves light on to pass information that the group count is 2 and that counting responsiblity has been passed to the Day Three Prisoner. If he can not pass 2, he keeps the counting responsiblity by turning light off.

Day Three:  If light is on, he becomes the counter (adding himself in) and turns the light off.  Note that he knows that his count starts at 2 plus his own status.  If the light is off, he knows that he is not the counter and must tell the First Day Prisoner of the next group his status: "on" for you now have the responsibility for counting me or "off" for there is no information or responsibility to pass.

At the end of the 100 days, you will have 33 or 34 counters (depending on what you do the last day).   You will still have some counters with only 1 (those First Day Prisoners who have been passed responsibilities and were not able to pass them on yet).  One would expect that the longer you go on, the more chance you will be able to slip these in to the main count.  The other counters will have variable counts.  You will have may counters with 3, some with more (if they have been a counter a few times) and the rest with 2.

The intuitive benefits of this method is that you have eliminated a lot of prisoners from all further responsiblities (including counters with 0 counts).   This may increase efficiencies against 8 or 10 fixed counters from cycles through the prisoners because prisoners can not report because the light is being used already.

Please let me know if you think this method  has some promise in shaving some time off the optimum method.

Ben

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Phil on Jan 29th, 2003, 6:13pm
I can't compete with the solvers of this riddle figuring out optimum techniques, but I just thought I'd throw a monkey wrench into your calculations. The numbers would come down significantly if prisoners could transfer more than 1 bit of information, would it not?
The riddle says the men are taken out of the room at the end of the day. It does not say when they're put in the room, but if they could convince the jailer to give them a full day in the room, in right after midnight, out right before midnight, then you can pass information in the temperature of the bulb. The bulb could be left on, or off but hot, or off but warm, or off and cold. That's double the info, and I bet the extra info could be extremely useful.
The other solution would be to always leave the bulb off, but unscrew it slightly the first time you enter the room. If each person could accurately rotate it the same amount, you'd know exactly how many people had been in the room (100 fifteen-degree turns might completely room the bulb, for example). If not, then simply the amount it was unscrewed in broader, 90- or 180-degree terms could be an additional way to pass information.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by just some moron on Jan 31st, 2003, 9:16am
bah the best sollution would be to take off a shirt or a shoe or a sock if it's your first time in the room so when there's 100 of them you can tell the warden all 100 have been in the room the riddle never asked for how many days it would take so i don't know what's everyone doing  ^_^

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by steve z on Feb 9th, 2003, 7:26pm
It is obvious that just some moron's reply is the best.  I thought of a similar one right off the bat.  They all agree at the meeting for the first person to break the bulb into 100 pieces and put 99 in the corner of the cell.  The one peice he takes with him- because it was his first time in the cell.  This goes on until all the peices are gone.  That and moron's solution are the quickest and most logical ways aside from putting marks on the wall for first timers.  It is most likely that prisoners do not have the capacity to run 100-day cycle probabilities in their head, or organize a leader.  Anyways, that is the solution, there is no other.  If you think there is, e-mail me at szellers@umd.umich.edu.  Peace.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by steve z on Feb 9th, 2003, 7:33pm
For clarification, I only read the first page of replies and didnt realize my exact reply above had already been posted, although I expected it to be since there were six pages already here.  peace

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by GRAND_ADMRL_THUORN on Feb 12th, 2003, 11:34am
theres nothing more that I hate, than a riddle that has no "DEFINATE" answer, but o-well, at least its forced us to think and that is always a GOOD thing.   ;D

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by john on Feb 12th, 2003, 2:05pm
I just thought of this, and I didn't feel like scanning through the 6 pages of previous posts to see if this has been suggested, but here goes:

Take the average life of a lightbulb and divide by 100.  This number (x) is the number of hours that each prisoner should leave the lightbulb in the "on" position whenever they go to the living room, but ONLY THE FIRST TIME.  After that, they don't touch the dang thing.  As soon as a prisoner witnesses the bulb burned out, he/she can assume that all of the prisoners have been to the livingroom.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Icarus on Feb 12th, 2003, 3:51pm
That is an interesting idea, John, and no it has not been suggested before. Unfortunately, light bulbs vary a lot in lifetime, and this also depends on how often they are turned on and off. It's also true that the lifetimes are longer than 2400 hours, so the prisoners would each half to visit more than once to get their allotted bulb time in.

Still - this is the first alternative to the counting methods that does not depend on conditions not mentioned in the puzzle. (Okay - it does depend on someone knowing the lifetime, and on the bulb being fresh at the start.)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by poopie on Mar 2nd, 2003, 8:57pm
stumbled on this riddles page.  nice.
as for this problem:

Each day, the warden picks a prisoner equally at random, and that prisoner visits the central living room; at the end of the day the prisoner is returned to his cell.

the light bulb can convey 2 bits of information

is it on or off
is it hot or cold

if left on long enough by the end of the day when the warden takes the prisoner back and picks up the next prisoner, that prisoner could see if the bulb is on or not and also feel if it's hot or cold.

dunno if this helps :p

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by harpanet on Mar 8th, 2003, 11:17am
Whew, this is some thread! I have read most of the posts (not the same as understanding though  :-[).

I notice that some of the posts talk about 'day #' and use the days to synchronize or drive the solution. However the riddle now states that the cells are windowless and soundproof. Therefore is it not impossible for any of the prisoners to track time and, by extension, how many visits there have been?

Although I suppose there may be daily routines that allow them to keep track (e.g. slop out, meal times).

Is a multi-stage solution possible if time cannot be tracked?

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Jeremy Randolph on Mar 13th, 2003, 6:33am
Whew… seven pages. Ok. I reread the original riddle and saw that a solution had been found that put the average solve time at about 11 years (instead of 27). A while ago I though up the single leader solution, so I figured I would try to figure out this 11 year solution before coming back to the forum. Well, I got something like the binary passing of information. But my way was not ideal. Basically in stage one I had 50 designated counters, and 50 designated passers of information. In stage 2 however 14 of the passers from the last round became pseudo-counters (in that they pretend they counted a second prisoner when actually they did not). This makes it seem like there are a total of 128 prisoners, instead of 100, which makes halving the number of prisoners much more neat and tidy each round. It goes from 64 counters, to 32 to 16 to 8 to 4 to 2 to 1 person who counts 128 prisoners. My average time was about 13 years… 15 if I wanted to be conservative and try to get them out in round one pretty much all the time. A lot of tweaking can be done by adjusting the round lengths. I have 1000, 900, 800, 700, 600, 400, and 200 days for each respective round. Back in high school I took a statistics class and I learned all about standard deviation and what not… so I figure the way to optimize these round lengths (actually the round lengths you all came up with, because yours are better) is to calculate the standard deviation for each round, and make the rounds with a bit higher deviation a little more conservative.

I also wrote a C program for the solution I came up with… but it’s a hell of a lot longer than what AlexH posted. Yeesh… well this is my first programming class…. Ummm… actually I have a test right now.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Trichoplax on Mar 14th, 2003, 7:40pm
Here's a semantically pendantic solution:
Apologies if it's been mentioned already (I don't feel like wading through 7 pages...).

"There's a central living room with one light bulb; the bulb is initially off."

Notice how this does not state that the bulb is connected to a fitting! Of course, were it simply a loose bulb, it WOULD be initially off... And there is nothing in the riddle which disqualifies it from being a loose bulb.
Thus, all the prisoners have to do in the meeting beforehand is decide upon a sequence of 100 different positions of the bulb in its loose state, with those new to the room placing it in the next positions and those who are not leaving it...

This action complies with the dictionary definition of the term "toggle", as "To alternate between two or more electronic, mechanical, or computer-related options".

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Wil on Mar 17th, 2003, 8:37pm
Back to the bits of information thing...

The light can store a single bit (either on or off).  This is a good start.  How 'bout if one of the prisoners also stores state? (i.e. every time he sees the light on, he increments his internal counter, then toggles the light off.  If any other prisoner sees it off, he turns it on, otherwise, he just leaves it alone).

Since the state storing prisoner knows that the light was originally off, then counting and toggling 99 lit bulbs should be all he needs to do to get them inducted into Mensa right?

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Wil on Mar 17th, 2003, 8:50pm
Oops.  looks like that was already suggested but not optimal.  That'll learn me about not reading all prior posts on a subject.

Won't happen again.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Wil on Mar 22nd, 2003, 11:40pm
I was examining the probabilities that 100 prisoners have each entered the room at least once, but I couldn't see how they were calculated.  Any help as to how you might calculate the probability as a function of the number of days?

Title: :(Re: How to Solve 100 prisoners & Light bulb?
Post by Boody on Apr 1st, 2003, 8:44am
I think that my favorite riddle.
I found a basic solution and I would only know if this is the commun solution that everybody found and that take 27-28 years ?

[ hide ]
[hide]
Only one prisonner count from 1 to 99 when he see the light on and then switch off the light (he's designed by all or he is ramdomly choosen the second day for example).
The others have to switch on the light the first time they see it off (and do nothing else).
[/hide][ /hide ]
The number of the day is not taken into account (several prisonners by day is possible), and then we lost information. This is not a optimal solution.
:(
I'm trying to search with several counters or with counters of counters and by taken days into account but no genius idea had come in my mind.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by william wu on Apr 1st, 2003, 10:34am
yes that is the common solution; congratulations

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by DanS on May 12th, 2003, 11:37am

on 03/22/03 at 23:40:25, Wil wrote:
 I was examining the probabilities that 100 prisoners have each entered the room at least once, but I couldn't see how they were calculated.  Any help as to how you might calculate the probability as a function of the number of days?

I think that the chance of all 100 prisoners having been in the room after D days is:

[ 1 - (99/100)^D ]^100

1000 days -> 4.3e-3
1500 days -> 2.8e-5
2000 days -> 1.9e-7

I might not guarantee my release, but at least I'll get out of jail before most of the other solutions (or die trying).

My first solution was to break the lightbulb, so I guess that shows what kind of puzzle-solver I am.... :)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Vivek on May 12th, 2003, 8:46pm
Since I am incapable of thinking the optimal solution, I will change the topic. Solve the puzzle when the original state of the bulb is not known. (I hope no-one has already mentioned it).

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Leo on May 13th, 2003, 6:57am

on 05/12/03 at 20:46:40, Vivek wrote:
 Since I am incapable of thinking the optimal solution, I will change the topic. Solve the puzzle when the original state of the bulb is not known. (I hope no-one has already mentioned it).

This puzzle (with some modifications) was given on the PBS show Car Talk. You simply count to 2*n-1, and whoever was allowed to turn the bulb once, is now allowed to turn it on twice.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Leo on May 13th, 2003, 9:34am
The multiple counter algorithm, as given in the PDF paper http://www.ocf.berkeley.edu/~wwu/papers/100prisonersLightBulb.pdf
is wrong. Whenever someone has to turn the light off at the end of a stage without incrementing his counter, a message is lost and the count will never converge. Therefore, this message must be carried to the next occurrence of that stage:

Here are the missing cases:

• If a drone, or a "sub-completed" primary counter (who already counted to Cp, and cannot increment his 1st stage counter anymore) has to turn the light off at the end of stage 1, he will have to turn the light on whenever he has a chance during following occurrences of stage 1. This may result in a Drone having to turn the light on twice or more - it's OK.
• If a previously completed secondary counter leaves the light on
at the end of stage 1, he will have to turn it on whenever he has a chance during stage 1.
• If anyone but the primary counter has to turn the light off at the end of stage 2, he will have to turn the light on whenever he has a chance during following occurrences of stage 2

What are the optimal stage durations for this algorithm? I got good results with 500/500.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by rmsgrey on May 14th, 2003, 1:22pm

on 05/12/03 at 20:46:40, Vivek wrote:
 Since I am incapable of thinking the optimal solution, I will change the topic. Solve the puzzle when the original state of the bulb is not known. (I hope no-one has already mentioned it).

This is only interesting when the prisoners have no way of knowing that they're not the first person into the lounge - if the first person to enter knows they're the first person, and everyone else knows they're not, then the first one in simply leaves the bulb as he would if he'd come in to find it off in the case with known initial state...

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by rmsgrey on May 14th, 2003, 1:33pm
Something I don't think anyone's mentioned yet: many light switches are actually ternary devices - in addition to the stable "on" and "off" states there's often (in theory always) an unstable equilibrium point in between. Of course, there are switches where the equilibrium is sufficiently unstable that it wouldn't be a reliable means of passing data - and in order to be completely certain you'd need the third state to have an infinite half-life...

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by James Fingas on May 14th, 2003, 1:55pm
rmsgrey,

That's a good point. You could probably find a small range over which the light switch was stable, and use that to encode a real number, specifying which people had already been there. You might say: but without an infinite half-life, we can't give a guaranteed answer.

Well here's something to think about: I'm sure there is a finite half-life for the supposedly stable on & off states as well. Ignoring that the prison guards could decide they wanted it on or off, or that there could be an electrical short (or regulation change) requiring the switch to be replaced (and who knows what position it would end up in), I'm sure we could come up with some natural phenomena that could trip the switch (large current spike? Infestation of large high-jumping frogs? earthquake? tornado throwing around shards of glass?).

So, in allowing a (presumably large) half-life for the switch in an intermediate position, we're not necessarily violating the sanctity of the solution...

Although we might get into corruptibility of our data, especially since you'd need very accurate placement of the light switch to indicate 2^100 possibilities...

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Leonid Broukhis on May 14th, 2003, 2:37pm

on 05/14/03 at 13:22:33, rmsgrey wrote:
 This is only interesting when the prisoners have no way of knowing that they're not the first person into the lounge - if the first person to enter knows they're the first person, and everyone else knows they're not, then the first one in simply leaves the bulb as he would if he'd come in to find it off in the case with known initial state...

The problem statement does not say that the ordeal is guaranteed to start on the next day after the prisoners are allowed to meet. The only thing we know is that after it starts, there will be one visit to the lounge per day. This reading of the problem invalidates one of the solutions given in the PDF paper, BTW.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by andrefmedeiros on May 19th, 2003, 8:10pm
As the switch have just 2 states, if the first guy that enter twice in the room turns on the light and just the guys that enter by the firs time in the room turn it off, the firs guy can count until the light to be turned off 99 times. If they teh day it started, he can discount from 99 the days until ho enter the secont time. But it runs in 10000day (e.g. 27 years) in average.

But if we assume that the light bulb can be touched and disconnected, it creates more two states. So, it allow the third guy that enter twice in the room starts the countdown and when he enter there again he can count up to 3 guys that was there by the firs time, reducind the average time it runs to less than 3000 days (e.g. 9 years).

What do you think? (Sorry for my english, because i'm brasilian and I'm still learning this language)
;D

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Volume 3 Xanos on Jun 5th, 2003, 11:40pm
I'm afraid I don't have a good algorithmic solution, but I thought another hack might be useful to keep minds thinking.

The first guy in smashes the light bulb into greater than or equal to 100 pieces (this may cause injury to him, but that seems like a small price to pay). Then he can arrange the pieces so they're easy to find for the other prisoners.  When he leaves he takes all but 99 pieces.  Each time a prisoner comes to the room for the first time he takes a piece away with him.  When there are no more pieces they can make their assertion.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Volume 3 Xanos on Jun 6th, 2003, 6:03pm
My apologies,

I was reading through more of the posts and someone else had already suggested the smashing light bulb solution. Would the moderator please remove my posts.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Zeke the Geke on Jun 23rd, 2003, 1:38pm
Here's an idea someone could turn into a new problem -- how many posts does it take on a single thread to make the thread self-perpetuating?  That is, due to factors such as perceived complexity, length and clarity of posts, intelligence and humour of submissions, and failure to read previous posts, does a thread eventually reach the point where it will continue to thread-infinity?  I think one of our uberpuzzlers ought to take a stab at this one!

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by THUDandBLUNDER on Jun 23rd, 2003, 4:58pm

Quote:
 I was reading through more of the posts and someone else had already suggested the smashing light bulb solution. Would the moderator please remove my posts.

Quote:
 does a thread eventually reach the point where it will continue to thread-infinity?

I suppose one could model a thread as an n-dimensional self-avoiding random walk.

However, ever-vigilant sentinel Überpuzzlers (such as wowbagger)
ruthlessly ensure that all non-avoiding walks are absorbed!

:P

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Chewdogscp on Jul 11th, 2003, 7:42pm
Ok, i'm not sure if this has been sugested before and i appologize if it has. My idea is kind of like the one where you put a mark on the wall, but i would guess that the prisoners are not allowed to have any kind of writing utinsel or anything to write on the wall....

Anyway, i assume that the light bulb in the room is a conventional bulb and is made of glass that can be broken. In this situation the first prisoner on the first day could break the bulb into a hundred pieces and make a stack of one hundred broken glass shards (hopefully he wont cut himself in the proccess  ;)). Then he moves one piece of glass into a seperate pile.

Each prisoner from that day on will then remove one piece of glass from the original stack to the second stack ON THEIR FIRST VISIT TO THE ROOM WITH THE BULB. If they were to visit the room twice they are not allowed to touch either piles of glass.

When the 100th prisoner enters the room will then know that all 99 other men have been in the room for he will see the shards that represents each of the men.

I hope that works, once again i'm sorry if that has been thought of before or if it violates any rules of the puzzle.  :P

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by rmsgrey on Jul 14th, 2003, 4:39am

on 07/11/03 at 19:42:59, Chewdogscp wrote:
 Ok, i'm not sure if this has been sugested before and i appologize if it has.

*points at post 5 posts up the page*...

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by myself on Jul 19th, 2003, 11:30pm
can somebody post the link to the original riddle? Or tell it again, but i cant seem to find it...

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Icarus on Jul 20th, 2003, 11:33am
It's the fourth riddle on the Hard Riddles (http://www.ocf.berkeley.edu/~wwu/riddles/hard.shtml#100prisonersLightBulb) page.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Sep 8th, 2003, 7:56am
Just to try and drive someone else crazy (misery loves company):

I've been mulling over the setup for this problem and wondering how much computational power the prisoners collectively have. Obviously, individually they are capable of solving any solvable problem, so there has to be some means of preventing any one prisoner from starting with all relevant data (unless they then aren't allowed to be the ones who make the final declaration). The input to the system then has to be the order in which prisoners get taken to the room. Assuming appropriate coding on the input, what problems can be solved by the collective prisoners?

Title: Re: 100 prisoners & a light bulb
Post by zack smith on Sep 9th, 2003, 9:56pm
my guess is that the prisoners were numbered  from 1-100 and they would carve there number into a wall for ever time they are in the room. 8)

Title: Re: 100 prisoners & a light bulb
Post by Steve Burns on Sep 19th, 2003, 3:46am
Wow, 8 pages of posts... this is my first time on this site and this one really just smacked me after i read it... Now... This riddle really has nothing to do with days because, if the inmates are taken at random, then one person could go a few times before another goes at all.  What needs to happen is that the inmate must toggle the switch if it is their first time in the living room.  The start positions is off... so seeing it takes 2 toggles to turn a switch from on to off, when the light goes out for the 50th time, then the next prisoner can assert that all prisoners have been in the living room.... Anyone see any flaws with that? ... email me response at "zyth13@hotmail.com".... later all

Title: Re: 100 prisoners & a light bulb
Post by Steve Burns on Sep 19th, 2003, 4:28am
Sorry folks about the last post... i missed that the prisoners couldn't see the light..... my new idea... the first prisoner in should break the bulb into 100 pieces and take one... each following prisoner should take a piece of the shattered bulb until none are left... that is when the assertion can be made...

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 19th, 2003, 3:50pm
Welcome to Wu's Forum, Mr. Burns! :)

I do feel compelled to point out that you are only about the 20th or so person to suggest this. (There's a lot of stuff in those 8 pages.)

There are plenty of other so-called "outside the box" solutions too. And while in any sort of real-world application, they are often preferable, in this case they actually bypass what makes the puzzle interesting: the challenge of finding the best "inside the box" solution.

Title: Re: 100 prisoners & a light bulb
Post by kofman2155 on Oct 8th, 2003, 8:05pm
I take it, no answer has been provided yet. Is there a point at which Mr. Wu provides us with one?

Title: Re: 100 prisoners & a light bulb
Post by Mike_V on Oct 8th, 2003, 8:35pm
Actually, several very good answers have been given in the 8 pages of this thread. Though I don't believe any have been proven to be optimal.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Oct 8th, 2003, 8:57pm
AN answer is to be found in the first few posts, but it is definitely not optimal. A variation was made of it which was essentially the answer that William had, but this too has been significantly bettered. If you will go ahead and read though the posts, you will see some very clever ideas for improving the outcome.

However a proof of optimality does not seem likely to me.

And no, William does not provide the answers to his puzzles. Those of us who haunt these forums on a regular basis would have it no other way. Nor do we provide the answers to the puzzles we post. The finding of the answer is, and should remain, the responsibility of the readers, not the poster (who should say so if he or she does not know the answer).

Title: Solution in 600d. Re: 100 prisoners & a light bulb
Post by dimitre on Oct 14th, 2003, 5:03am
Hi,

I have a solution which works in an average of 600 days.

Will anybody be interested if I publish this solution and the program that demonstrates it?

Cheers,
Dimitre.

Title: Re: Solution in 600d. 100 prisoners & a light bulb
Post by towr on Oct 14th, 2003, 5:16am

on 10/14/03 at 05:03:24, dimitre wrote:
 I have a solution which works in an average of 600 days.Is it good or bad?
That would be pretty good, since the more common solutions on average take at least a decade or two, and yours less than two years.

Quote:
 Will anybody be interested if I publish this solution and the program that demonstrates it?
Please do, it'd be interesting to see a new approach..

Title: Re: 100 prisoners & a light bulb
Post by dimitre on Oct 14th, 2003, 7:04am
The solution is as follows:

The time is divided in iterations. Every iteration is exactly 100 days.

Every prisoner has two states:
registered
unregistered

All prisoners are unregistered before any prisoner has visited the room.

When a prisoner visits the room:

If this is the first day of an iteration, he lights the bulb.

If the bulb is lit and the prisoner is unregistered, he
becomes registered
. The prisoner also remembers the
number of the iteration, at which he registered.

If the light is on and the prisoner visits the room for a
second time during the iteration in which he became
registered, he turns off the light

If this is the last day of the current iteration and the
light is on and the prisoner is either unregistered
or has been registered on a previous iteration
, then
he announces that all prisoners have already visited the
room.

The .Net C# project is in the attached PrRiddle.zip file.

This is a console program, which runs the problem 1000 times and reports the average number of days that were needed for the liberation of the prisoners.

Do enjoy.  :)

Dimitre.

Title: Re: 100 prisoners & a light bulb
Post by dimitre on Oct 14th, 2003, 7:15am
Ooopsss... I don't see the attached file...

Sorry, here's just the .cs file:

using System;
using System.Collections;

namespace PrRiddle
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class TestPrRiddle
{

/// <summary>
/// The main entry point for the application.
/// </summary>

public static ArrayList unRegistered = new ArrayList(100);

static void Main(string[] args)
{
bool theBulb = true;
int iteration = 0;
ushort day = 0;

ArrayList thePrisoners = new ArrayList(100);

for(int i = 0; i < 100; i++)
{
}

Random rand = new Random((int) DateTime.Now.Ticks);

int numruns = 1000;
int totalDays = 0;
int iter;
for( iter = 0; iter < numruns; iter++)
{
while(Prisoner.totalRegistered < 100)
{
iteration++;
theBulb = true;

for(day = 1; day <= 100; day++)
{
int next = rand.Next(0, 100);
((Prisoner)(thePrisoners[next])).visitRoom(theBulb,iteration, day);
}
}
totalDays += (iteration - 1) * 100 + day;
}
Console.WriteLine("Average days: {0}", ((float)totalDays) / numruns);
}
}

class Prisoner
{
public static int totalRegistered = 0;
public static int totalUnRegistered = 100;
bool registered = false;
int iterRegistered = -1;

public void visitRoom(bool theBulb, int iteration, ushort day)
{
if(theBulb && !registered)
{
totalRegistered++;
totalUnRegistered--;
registered = true;
iterRegistered = iteration;
TestPrRiddle.unRegistered.Remove(this);
return;
}
//else
if(registered && iterRegistered == iteration)
theBulb = false;
}

}
}

Title: Re: 100 prisoners & a light bulb
Post by BNC on Oct 14th, 2003, 7:27am
Dimitre,

Maybe I don't understand your solution, but let's examine the following (unlikely) case:

Mark all prisoners with 1..100.

BEGIN: all prisoners are unregistered.

1st Iteration:
Prisoner #1 is called every single day (100 times)

After 1st iteration:
prisoner #1 registered; Prisoners 2..100 unregistered.

2nd iteration:
Prisoner #1 called first 99 days. He tyrned on the light on the first day, and didn't turn it off as it wasn't second time during the iteration in which he became  registered. Therefore, the light is on.
Day 100 of 2nd iteration, prisoner #2 is called. It is the last day of the current iteration and the  light is on and the prisoner is unregistered  => he announces that all prisoners have already visited the room.

Result: all prisoners die on the 200'th day  :'(

Title: Re: 100 prisoners & a light bulb
Post by BNC on Oct 14th, 2003, 7:40am
In addiition, I tried looking at your code. I'm not very fluent at C, but as far as I understand, each prisoner maintains a record of total number of registered and unregistered prisoners -- and the individual prisoner has no way of knowing that...

Please forgive me if I didn't understand the code (quite likely).

Title: Re: 100 prisoners & a light bulb
Post by dimitre on Oct 14th, 2003, 8:21am
You're absolutely right!

My program shows that the prisoners will be unsuccessful from 3 to 7 times in one million.

So, it seems at least not too risky as a strategy.

I don't know the statistics, but probably flying on a plane or having a tooth pooled is much more dangerous.

Certainly, I must think about an exact solution -- sorry I have been dealing with this problem just since two days.

Cheers,
Dimitre.

Title: Re: 100 prisoners & a light bulb
Post by dimitre on Oct 14th, 2003, 8:26am

on 10/14/03 at 07:40:46, BNC wrote:
 In addiition, I tried looking at your code. I'm not very fluent at C, but as far as I understand, each prisoner maintains a record of total number of registered and unregistered prisoners -- and the individual prisoner has no way of knowing that...Please forgive me if I didn't understand the code (quite likely).

No, this is OK. The number of registered prisoners is a static property (belongs to the whole class), not an individual property of any Prisoner.

It is not used by any prisoner.

The program itself finds out when all prisoners have registered.

Of course, in real life the last prisoner will announce the event.

As the program simulation showed, the chance of an eror is 3 to 7 in one million.

Cheers,
Dimitre.

Title: Re: 100 prisoners & a light bulb
Post by BNC on Oct 14th, 2003, 9:37am
It is true that the risk of 3-7/1000000 is small, and in real life would probably be worth taking. Previous suggestions along this line included calculating a number of days after which the probability of fail is below a given threshold.

However, the challenge in this riddle is to be 100% sure saving the prisoners at a minimal number of days.

Title: Re: 100 prisoners & a light bulb
Post by Dimitre Novatchev on Oct 14th, 2003, 11:08am

on 10/14/03 at 09:37:34, BNC wrote:
 It is true that the risk of 3-7/1000000 is small, and in real life would probably be worth taking. Previous suggestions along this line included calculating a number of days after which the probability of fail is below a given threshold.However, the challenge in this riddle is to be 100% sure saving the prisoners at a minimal number of days.

While I am not arguing about this, a good solution to a statistical problem has to be statistical -- and this particular problem is a good proof of that.

The exact solution (yes, I found it myself -- one "responsible" prisoner will count every new registration and such a registration will happen only once per iteration) bears no risk, but the people will have to stay in jail much longer (and the probability to die while staying there is higher than the probability to die if they implement the statistical solution).

To put it in other words, a failure using my solution highly contradicts the condition that the choice of a prisoner is made in a truly random way.

I also plan to improve my solution -- by studying the "failure data" I would probably be able to modify the solution to something like this:

"Only report success if the iteration number is higher than 7"

Something like this may significantly reduce even this tiny probability.

Cheers,
Dimitre.

Title: Re: 100 prisoners & a light bulb
Post by James Fingas on Oct 14th, 2003, 12:21pm
Dimitre,

Your code doesn't appear to work the way you say it does. Nowhere do I see a check on whether or not the light is on on the last day of the iteration. Instead, I see the check "while(Prisoner.totalRegistered < 100)", which, as BNC pointed out, is information no prisoner has.

There are other strange things in the code as well. For totalDays, you add "totalDays += (iteration - 1) * 100 + day;", but there is no point in adding "day", because the for loop for the "day" variable will only end when day == 101.

According to my analysis, your program randomly selects prisoners in "iterations" of 100 days, and after they've all visited the living room, quits at the end of the next iteration. So your program never fails, but it assumes prisoners have information they couldn't actually have. To fix your code, I would do the following:

-replace "while(Prisoner.totalRegistered < 100)" with "while(theBulb == false)"
-this would also necessitate replacing "bool theBulb = true;" with "bool theBulb = false;"
-add two more 'tally' variables: numFailureRuns and totalFailedDays, to tally up the number of times out of numruns this method fails, and the total number of days that this takes.
-when you tally up the days, use an if statement on Prisoner.totalRegistered to see if it failed or succeeded, and add the number of days used to either totalDays or totalFailedDays.
-now you can calculate statistics for both success and failure separately, and also the probability of failure.

That being said, fixing the program doesn't fix the underlying method. We are looking for a failure-proof method, and your is ultimately an opt-out method. If nobody shows up who will turn the light off, then you assume everybody is registered and nobody appeared twice. No opt-out method can work, because you're never guaranteed that the right person will show up when you need them to opt out.

Title: Re: 100 prisoners & a light bulb
Post by Dimitre Novatchev on Oct 14th, 2003, 12:50pm
James,

Indeed I have found some bugs, which I'm now in the process of fixing.

As for finding an "optimal" exact solution, it will by definition be much longer than an optimal probabilistic one.

Therefore, it seems unlikely to me that the "common" solution can be improved radically.

Cheers,
Dimitre.

Title: Re: 100 prisoners & a light bulb
Post by Rezyk on Oct 14th, 2003, 7:00pm
When coding/thinking about this problem, I found it useful to use this generalized parameterization of previously suggested optimizations:

For each prisoner's visitation, he follows 4 steps:
1) If the bulb is on, lookup the previous day's passable items, add them to your inventory, and turn the bulb off.
2) Check if you have [winCondition] within your inventory.  If so, assert that all prisoners have visited.
3) If the day includes a creation/destruction, modify your inventory appropriately.
4) Decide whether or not to pass some items to the next visitor, based on the day and contents of your inventory.  If so, subtract the items from your inventory and turn the bulb on.

I've made up some pseudocode for the next sections; hopefully it's not too illegible.  Generally I list a number of days followed by the creation/destruction/decision/passing directives that apply within each of those days.

As an example, here's what SWF's 10/28/2002 system might look like (if I interpreted it correctly):

Code:
 Set each inventory to 1 token.Set winCondition to 100 tokens.first day: Pass 1 token.next day: Destroy 1 token.  If tokens>0, pass 1 token.next day: Create 1 token and 1 crown.  Pass nothing.Repeat 8 times {      next day: If tokens>0 and badges==0, pass 1 token.      next day: Create 1 badge.  If badges>1, pass 1 badge.}next day: If badges>1, pass 1 badge.next day: Pass nothing.next 2252 days: If tokens>12*crowns+11*badges, pass 1 token.next 1610 days: if badges>0 and tokens>10 and crowns==0, pass 1 badge and 11 tokens.Repeat indefinitely {      next 302 days: If tokens>12*crowns+11*badges, pass 1 token.      next 358 days: If badges>0 and tokens>10 and crowns==0, pass 1 badge and 11 tokens.}
Estimated mean: 3535.6 days
Standard deviation: 607 days
based on a sample of 11 million runs

Here's my new suggested system:

Code:
 Set each inventory to 1 token.Set winCondition to 128 tokens.first day: Create 28 tokens and 1 crown.  Pass 29 tokens and 1 crown.next day: If tokens==30, pass 30 tokens and 1 crown.next day: If tokens==31, pass 31 tokens and 1 crown.next day: If tokens==32, pass 32 tokens and 1 crown.next day: If tokens==33, pass 33 tokens and 1 crown.next day: If tokens==34, pass 34 tokens and 1 crown.next day: If tokens==35, pass 35 tokens and 1 crown.next day: If tokens==36, pass 36 tokens and 1 crown.next day: If tokens==37, pass 37 tokens and 1 crown.next day: If tokens==38, pass 38 tokens and 1 crown.next day: If tokens==39, pass 39 tokens and 1 crown.next day: If tokens==40, pass 40 tokens and 1 crown.next day: If tokens==41, pass 41 tokens and 1 crown.next day: If tokens==42, pass 42 tokens and 1 crown.next day: If tokens==43, pass 43 tokens and 1 crown.next day: If tokens==44, pass 44 tokens and 1 crown.next day: If tokens==45, pass 45 tokens and 1 crown.next day: If tokens==46, pass 46 tokens and 1 crown.next 2 days: If tokens==47, pass 47 tokens and 1 crown.Repeat 2 times: {      next day: If tokens%8>=1 and crowns==0, pass 1 token.      next day: If tokens%8>=2 and crowns==0, pass 2 tokens.      next day: If tokens%8>=3 and crowns==0, pass 3 tokens.      next day: If tokens%8>=4 and crowns==0, pass 4 tokens.      next day: If tokens%8>=5 and crowns==0, pass 5 tokens.      next day: If tokens%8>=6 and crowns==0, pass 6 tokens.      next 2 days: If tokens%8==7 and crowns==0, pass 7 tokens.}Repeat 3 times: {      next day: If tokens%4>=1 and crowns==0, pass 1 token.      next day: If tokens%4>=2 and crowns==0, pass 2 tokens.      next 2 days: If tokens%4==3 and crowns==0, pass 3 tokens.}next 380 days: If tokens%2==1 and crowns==0, pass 1 token.next 330 days: If tokens%2==1, pass 1 token.next 330 days: If tokens%4>=2 and crowns==0, pass 2 tokens.next 300 days: If tokens%4>=2 and (crowns==0 or tokens%4==2), pass 2 tokens.next 300 days: If tokens%8>=4 and crowns==0, pass 4 tokens.next 200 days: If tokens%8>=4 and (crowns==0 or tokens%8==4), pass 4 tokens.next 1650 days: If tokens>=8 and crowns==0, pass 8 tokens.next 500 days: If tokens>=4 and crowns==0, pass 4 tokens.next 300 days: If tokens>=2 and crowns==0, pass 2 tokens.Repeat indefinitely: {      next day: If tokens>=1 and crowns==0, pass 1 token.}
Estimated mean: 3532.0 days
Standard deviation: 752 days
based on a sample of 1 million runs

The gist of what happens:

The first 20 days is just Salem's leader selection (with a small tweak at the end).

Then there are 5 short cycles which attempt to consolidate tokens into groups of 8 and 4.  These are just an optional optimization -- not sure how beneficial they really are.

Next starts off as AlexH's binary stages: all the tokens are grouped into pairs, then these pairs are made into groups of 4, which are made into groups of 8.  Note that the leader often hoards tokens against protocol, due to greed or wisdom.

Then, for the next 1650 days, we switch to straight leader-collection of as many 8's as possible.  61% of all cases conclude during this stage with an average total of 3042 days.

If no conclusion is made after 1650 days, we presume that one of the previous consolidation steps failed, and start backtracking to send all missed groups of 4 to the leader, breaking up any missed 8's as well.  After a while, we presume that a smaller consolidation step failed and start looking for groups of 2, and then finally gather everything left as singles.

Title: Re: 100 prisoners & a light bulb
Post by SWF on Oct 15th, 2003, 7:39pm
Well done, Rezyk.  It is good to see some serious attempts at this problem. I tried out your method it works as advertised: after 750,000 tries got an average of 3531.5 days with SD of 751. There appears to be room for more improvement.  For example extending to first stage to 48 tokens from 47 gave a mean of 3530.5, but that was for only 500,000 tries.

Title: Re: 100 prisoners & a light bulb
Post by Rezyk on Oct 19th, 2003, 4:11pm
Thanks, SWF.  You're right; there is definitely room for improvement.  Most of the stage lengths have only been optimized to the best multiple of 30-100 days, as opposed to the best day.

Is there a well-established method one could use for efficiently optimizing the stage lengths to get a local minimum?  My clumsy manual guess-tweaking is rather slow/cumbersome.

Title: Re: 100 prisoners & a light bulb
Post by James Fingas on Oct 22nd, 2003, 7:56am
Here's another possibility that might cut down on the average time (don't know if anyone's investigated it yet). When a person creates the crown, they destroy one token, making 99 total tokens. We could then add up tokens in groups of 3 and 9, or 11 instead of groups of 2, 4, 8, etc.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Oct 22nd, 2003, 8:26pm
I still believe that the token/crown family of solutions is for a more restricted problem that guarantees that a person will go to the central room exactly on the day that the prisoners deem "first". Nothing in the rules prevents the warden from starting the procedure the  day of the original meeting, or the day after, or the next Monday.
Can the token/crown solution be adapted to the more general rules?

Title: Re: 100 prisoners & a light bulb
Post by gypo on Oct 23rd, 2003, 4:29am
Hi guys,

I believe I have a solution that lets the prisoners out in under 3500 days (mean 3489, st. dev. 664 based on 1,000,000 simulations).

The method is a standard {10,10} with ninety drones, ten counters (who have badges) and a single leader (who has a crown as well as a badge). The improvement on previous methods comes from the opening stage (stage 0), where the counters and the leader are decided. The rest is a standard {10,10}: stage 1, where the counters count up to 10; stage 2, where the leader counts the counters (and announces when he reaches 100); and then infinitely recurring stages 3 (shortened stage 1) and 4 (shortened 2).

As I said above, the improvement comes from a new approach to stage 0. I will describe the algorithm in two steps, first a basic version (which isn't very good but gets the basic idea across) and then an improved version which gets around a key limitation of the simple approach.

So, the basic algorithm. Initially all prisoners have a single token, zero badges and zero crowns. Stage 0 is 40 days long, which is divided into 10 cycles of 4 days each.

* At the start of each cycle the light is always off (see later).

* On day 0 of each cycle, if the prisoner has one or more tokens he turns the light on and subtracts one token from his inventory. If he has no tokens, he leaves the light off and adds a badge to his inventory.

* On days 1 and 2, if the light is off the prisoner does nothing. If the light is on and the prisoner has one or more tokens, he leaves the light on and subtracts one token from his inventory. If the light is on and the prisoner has no tokens, he switches the light off and adds d tokens and a badge to his inventory (where d is 1 on day 1 and 2 on day 2).

* On day 3, if the light is off the prisoner does nothing. If the light is on, the prisoner adds three tokens and a badge to his inventory and turns the light off. (So the light is always off at the start of the next cycle.)

* Whoever gets the badge during the first cycle also gets the crown.

The algorithm was inspired by Salem's leader selection; the idea was to repeat this a few times to get more of the benefit that makes the leader selection process worthwhile.

The main failure of this simple approach is that very often one prisoner ends up with two badges. This means that he has to count up to 20 during stages 1 and 3, which is enough to add about 200 days to the expectation.

I have discovered a neat way of almost completely avoiding this. Among other things, the modification depends on the following insight: if a prisoner has a badge, he is allowed to have a negative number of tokens. This is OK, because the leader counts only what the counters signal to him and can't announce until all counters have signalled (and are therefore no longer in the red).

The algorithm is then modified as follows:

* Initially, all prisoners have one token each, zero badges and zero crowns (same as before).

* On day 0 of each cycle, if the light is on, the prisoner gets a badge and three tokens. If the light is off he gets nothing. If he now has one or more tokens or one or more badge, he turns the light on and subtracts one token from his inventory, even if he ends up with a negative number of tokens. If the prisoner has no tokens and no badges, he switches the light off and gets a badge.

* On days 1 and 2, the prisoner does nothing if the light is off. If the light is on and he has a token or a badge, he leaves the light on and subtracts one token from his inventory. If the light is on but he has no tokens or badges, he turns the light off and adds d tokens and a badge to his inventory.

* On day 3, if the light is off the prisoner does nothing. If the light is on and he doesn't have a badge already, he switches the light off and gets three tokens and a badge. If the light is on and he already has a badge, he leaves the light on and does nothing.

* Whoever gets a badge during cycle 0 also gets a crown.

* On day 1 of stage 1, if the light is on, the prisoner gets a badge and three tokens, switches the light off and pretends it was off to start with.

This opening will result in somewhere between 14 and 25 drones (out of 90) being counted during the first 40 days, which gives you some idea of the power of the method.

I haven't really optimised the stage lengths very thoroughly, but this is what I used to achieve the 3489 days: stage 0: 10 cycles of 4 days; stage 1: 2000 days; stage 2: 1500 days; stage 3: 300 days; stage 4: 300 days.

Title: Re: 100 prisoners & a light bulb
Post by James Fingas on Oct 23rd, 2003, 9:55am

on 10/22/03 at 20:26:26, Leonid Broukhis wrote:
 Can the token/crown solution be adapted to the more general rules?

Maybe it can ... you don't know when things will start, but if you set up the stages so they repeated forever, you might be able to make it work. But you still need to know the initial state of the light bulb.

stage 1, stage 2, stage 3, stage 4, stage 1, stage 2, stage 3, stage 4 ...

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Oct 24th, 2003, 1:49pm
You don't need to know precisely when day 1 is, provided you know a day after which things will definitely have started. If so, you can agree an arbitrary "day 1"

It's just been pointed out to me that you don't need to know the initial state of the bulb, or the time of day one - the designated counter turns the bulb off at every opportunity; everyone else turns it on twice. When the count reaches 198, then either everyone's been twice, or the bulb started off on, and one person has only been once.
Re-reading the 2 lightbulbs thread, I noticed this had already been pointed out there too - in fact, starting everyone with two tokens works under the most hostile of possible conditions - where the warden can any prisoner to the room at any time, can set the initial state of the lightbulb to whatever he wants, listens in on the strategy session and wants to see the prisoners dead if possible, or imprisoned for arbitrarily long, but (in order to make any solution possible) has to follow a strategy that sees all prisoners visiting the room an infinite number of times before time omega (least infinite ordinal) if they don't claim before then.[/edit]

Anyway, cycling through states with an unknown start and known initial state has problems because the actual start time changes the value of the intial lit bulb.
 Except that if you know the bulb starts on, you simply invert your system[/edit]

Title: Re: 100 prisoners & a light bulb
Post by aznbrotha on Oct 27th, 2003, 6:11pm
umm i dunno if its already mentioned but the prisoners could mark tallies only the first time they go in (so the second time they can just sit around). whenever a prisoner that never been in there before sees 99 tallies then he knows that he is the 100th one, but if this was his second or more turn and he sees 100 tallies that means everybody has gone.
....Does it make sense?

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Oct 27th, 2003, 6:41pm
aznbrotha, yes in the 9 pages of this thread you can find this idea in various forms mentioned repeatedly.

The quest behind this discussion is what to do when these "outside the box" type answers are not allowed, so you follow the situation described. This is a tricky discussion which has already produced some very interesting ideas.

(One of these days, we are going to have to do as William suggested in creating the headers, and use it list the best solutions, and point out that the discussion is long past the "other solutions". But I was kinda hoping that a moderator more involved in this thread than me would take care of it! ::))

Title: Re: 100 prisoners & a light bulb
Post by halfwind on Nov 13th, 2003, 2:45pm
Can the prisoners make a mark on the wall?  So if he/she has been in the room before, they don't make a mark, but if going in for the first time, he/she makes a mark.  After you count 100 such marks, you can be certain that all of them have been in that room.

Now the light bulb.  Hmm.  Who needs a light bulb, ha!  And besides it does not say that the warden cannot or will not turn off the lights if the prisoner leaves it on.

Title: Re: 100 prisoners & a light bulb
Post by Bitter and/or Twisted on Nov 13th, 2003, 6:12pm
Congratulations, halfwit, you are the 10.000th person to propose that solution. Please accept this "I can't be bothered to read the current page, let alone the whole thread!" T-Shirt, with our compliments.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Nov 13th, 2003, 6:35pm
Bitter and/or Twisted: I would ask that you consider that being rude and insulting lowers other's opinion of you rather than the one you insult.

Halfwind - while I do not condone the behavior of this guy, if you would please read my post that immediately precedes yours, it might help you to understand the frustration we feel when someone keeps suggesting these same things over and over again that do not at all address the particular problem we are considering.

Title: Re: 100 prisoners & a light bulb
Post by Bitter and/or Twisted on Nov 13th, 2003, 7:11pm
Sorry, I was only joshing. Apologies to halfwind and any other offendees.

Title: Re: 100 prisoners & a light bulb
Post by GCR1320 on Dec 20th, 2003, 11:40am
Ahhh ummm I'm just looking around and although I didn't read all 9 pages I thought I would throw this one out there.

Each prisoner leaves something in the living room the first time they go (shoe, clothing, tooth, hair, etc.).

Once there are 100 items you know that each prisoner has been in the room.

Once again, this assumed that people can leave things behind, but it is the best thing I can come up with.  Because I do not believe the solution lies within probability.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Dec 20th, 2003, 11:48am
Apparently you didn't read much at all, because you can find many variations of this idea posted, some on the first page. The discussion moved long ago from consideration of these ideas to the question of what is the best procedure possible strictly within the parameters stated in the problem.

Title: Re: 100 prisoners & a light bulb
Post by GCR1320 on Dec 20th, 2003, 3:40pm
Well thanks for being an ass about it.

And no, this was not suggested on the first page of this thread.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Dec 21st, 2003, 11:49am
I'm sorry I offended you. I am only expressing my frustration with seeing that someone has posted to this thread, and checking in to see if they have had any new insight, only to find the same idea, which bypasses the very things that make this problem interesting, posted another time.

You are correct, the first appearence of the this concept (leaving markers in the room) is in reply #44 on the second page (unless I missed an earlier one).

It also occurs in replies #86, #131, #132, #145, #146, #169, #173, #178, #180, #205, #207, and of course your own reply(#211).

I should have been more courteous in pointing this out, though. (In the few posts preceding yours, you will see that I chided someone else for the same fault.) I apologise.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Dec 23rd, 2003, 9:22am
If you allow marking the wall as a form of leaving a marker (not exactly, but very closely related) then the first appearance is reply #13 - on the first page. Had I gone from memory, I'd have thought of that one as the first appearance.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Dec 23rd, 2003, 4:25pm
It's the same idea (each person leaves something in the room to indicate their presence), so yes, it does count and I was correct in my original statement after all (I missed it because I was scanning rather than reading the posts - there may well be other occurences too). That does not excuse being rude about it though.

Since no one else seems to be interested in doing it, I suppose I ought to summarize the thread like William originally intended with the headers. But it would take more effort than I want to invest right now, particularly since I have never bothered to comprehend the details of the more complicated solutions.

Title: Re: 100 prisoners & a light bulb
Post by SWF on Dec 23rd, 2003, 6:21pm
hat this thread needs is to be split into two pieces, or maybe lock it and put links to two new threads each with a summary at the beginning. First thread would go in the Easy section and include alternate intepretations of the question, such as allowing prisoners to check-in on a sign up sheet left in the room (or otherwise leave a mark). Second thread would go in the Hard section and address the intended problem.

For the Hard version, the question should be carefully rephrased. Maybe have a custodian return the room to the same condition each day before the next prisoner visits, except the light is left in the same on/off state. Or have 100 different lightbulb rooms with a common switch, such that each prisoner only ever sees two rooms: his own cell and his own light viewing/switching room.

Icarus, if you are looking for a volunteer to write summaries, I would be willing if given the go ahead, but not if they would just be more posts buried on page 10 of this thread.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Dec 23rd, 2003, 11:39pm
If you're willing to summarize it - I was thinking of a short description of each of the solution methods along with the expected release time - I would be glad to put a link to it in the header, similar to what I did with the 0.999... thread.

I would agree with you above having an easy version - except that I would call it trivial rather than just easy. If you leave open the possibility of prisoners leaving marks, then the solution is obvious, so what is the point in even asking?

Title: Re: 100 prisoners & a light bulb
Post by snaily on Feb 10th, 2004, 8:29am
*doubts this will get read or even matter, but here's my 3.282348 cents*

The riddle itself is open-ended and so naturally a lot of people are going to jump right for the tally marks on the wall or break the lightbulb theory. I understand why those are not generally accepted answers to this riddle. The guard brings them into the room and lets them fiddle with the lightbulb/switch/toggle mechanism, then apparently they just go back to their cells. The guard would notice things being tallied or broken or any other obvious attempt and would probably just cover those up (the riddle only says that they can toggle the lightbulb not do anything else, so the guard can just undo whatever else they do). But in order for the riddle to even have an answer we have to accept that the guard doesn't mess with the state of the lightbulb/toggle mechanism, otherwise all solutions wouldn't work. So whatever the prisoners do with their turn at the lightbulb dictates how quickly they can 100% exit prison. Fine ... so my first answer to this problem yielded the result of 2,000 days (or 1,600 depending).

I read through the 9 pages and I like a lot of the answers, however the point is to find an "optimal" solution using only the lightbulb/toggle and nothing else, and with those conditions 2,500+ days is ridiculously high. I am semi-intelligent but when the binary solution started to get into the 4th or 5th page I had trouble not getting dizzy and falling out of my chair. Ultimately, that system, although complex, and requiring extensive knowledge and laser-cunning, somehow works, it's terribly slow.

Now some people have alluded to out-of-the-box solutions and unfortunately none have really typed out the specifics, so the needlessly complex "I have a degree in computers and math and am not afraid to show it" system still stands as "optimum". Hopefully some people will think otherwise after this post.

This riddle involves a light bulb and presumably a switch that turns it off and on. I don't know about the countries these people are from, but in America (and in most places that are of this world) people don't have to screw in and out lightbulbs to turn them on or off ... we have like ... buttons and stuff for that. Now lightbulbs on Earth typically do screw in and out and can typically screw a full turn without showing any outward sign that this has happened. In other words, turn a lightbulb 1 turn in it's socket, balance it, and then walk away. From a distance can you tell that it's not fully tightened ... of course not.

So how many "states" can a lightbulb/switch situation be in?

1) bulb off switch off
2) bulb half turn switch off
3) bulb full turn switch off
4) bulb screwed in tight switch on (light on)
5) bulb turned slightly (like 1/4 or maybe half) switch on (light on)
6) bulb turned full turn switch on (light would be off)

So using 1 as the default position you can do a simple leader scenario. Pick a leader who is able to count. Then tell everyone the order of light bulb progression. Half turn, full turn, screwed in and on, turned slightly and on, switch on but light off. If you enter the room and the light isn't done it's progression then you toggle it. If you toggle then you're done forever, never touch the light or anything again. If it's done it's progression when you enter, then wait til the next time to touch it. When the leader/counter enters the room he can tell whether 1, 2, 3, 4, 5, or 0 new people have been there. Add that number. When it gets to 99 you are free. With an average of 100 visits per time in the room you would need 20 sequences of 5 counts, so 2,000 days. Let's give or take a big margin and say 1,000-3,000 days expected or about 3-8.5 years with just under 6 as the average expected time. Sure beats a decade.

Now if the guard has the ability to fiddle with the bulb and switch then you are all negated. All of the prior solutions fail instantly. He could turn the bulb on or off or do anything, so the riddle is meaningless. If the guard can't touch the bulb or switch directly, which the riddle implies, only the prisoners can, then my method (which I'm sure a few have hinted at in less word) is entirely valid. The guard standing at the door and looking at the bulb will be physically unable to tell if it's semi-turned or not, and all but the last step the switch position matches the light (but you can ignore that one and still get 2,500 days as a total if you wanted).

This solution doesn't exactly think-outside-the-box, it just uses common sense. It was the first solution I thought of and as such it can probably be improved to even less days by someone who knows more about math. I get the feeling that anyone who doesn't use the "binary-math-anal" solution will get told that they are doing it wrong, but it's actually a simple problem if you think about it for a second.

You can either have 100 prisoners all know and understand a computer based language thingy that even I, a somewhat intelligent person didn't even begin to grasp, then have them not only count days (how can they do that? even if they get meals they can't see the sun, so can a human really be expected to know the difference between 12 hours and 8 hours, 2 meals a day or 3 meals a day? i doubt it), but they would also have to wait the decade to accomplish this. I couldn't follow the binary system for 10 seconds much less 10 years.

or ...

You can have 100 prisoners twist a lightbulb either halfway or one full turn, leave the counting up to the smartest guy (the one that has an IQ over 70) and then trust that they will be able to determine given ample time whether or not a lightbulb is in fact twisted or not by ... like twisting it to test.

Since I want to be totally scientific and mathematical, could someone please spend 8 years writing a C++ or other program to determine the statistical probability that a group of 100 people who perfectly understand binary will fail to understand the concept of twisting a lightbulb?

Okay, okay, I apologize for the sarcasm, because I think all answers that fit the riddle are correct ... it's just a matter of whether you want to go a certain route or not. On Willywu's island of death you can either work your butt off and then still burn to death (possibly) or just beat the riddle and die and go to heaven the winner. In the poison drinks one you can either worry about prisoners and algorithms or you can just give the wine in droplets (mixed in water) to farm animals and then you beat the riddle and everyone lives to toast (and the animal that dies can be thrown into a river somewhere). And in this puzzle you can either refuse to touch anything other than the switch going up or down and keep those poor people in jail until they are old men, or you can leave obvious clues and hope the guard just doesn't notice or mind, or you can do it my way and get out fairly quickly without anyone having to be intelligent to do it.

It's all up to how you look at it.

Title: Re: 100 prisoners & a light bulb
Post by godskook on Feb 10th, 2004, 8:38am
Since the riddle states explicitly that toggling the bulb is legal, my suggestion is to have a second indicator, i.e. the bulb.  The states of the bulb are (Tight, snug, loose, broken).  Although this adds to the efficiency of any solution, I should note that these may not be legal.

Tight and loose are legal as they are both easy to tell

snug is suspect because the exact definition may vary among the prisoners.

broken is doubtful because a replacement bulb would be required and that was not given in the problem

this adds to the speed of the solution by changing the numbers the room can hold from (0 to 1) to (0 to either 3,5, or 7)  I don't know probability so I can't say how much time is saved by this idea, but I do know it is legal.

Title: Re: 100 prisoners & a light bulb
Post by towr on Feb 10th, 2004, 9:35am
There is a solution for 100 days, but the prisoners need to be very dedicated.. Probably members of a cult as well..

All that's needed is that they kill themselves the same day they are led into the room. The last survivor can then go free on day 100. (That's assuming, of course, the guard doesn't feel inclined to drag around dead bodies)

Title: Re: 100 prisoners & a light bulb
Post by snaily on Feb 10th, 2004, 10:28am
Bizarre solutions that maybe we'd be better off if I didn't post (or words to that effect):

The first prisoner could kill the guard and steal his clothes (then maybe have a fashion show ... i mean release the others)

You could devise a really great plan then whisper to one guy, on your 4th trip just say "we've all been here" and cross your fingers, but don't tell anyone I said that

After a person goes to the room have them refuse to go from then on, they can tell the guard, ahh, just pick someone else today, I'm enjoying isolation ... when a person gets taken there like 27 times in a row, they can assume they are the last

They could just spend their lives in a regular jail and not agree to play the game, besides they probably deserve to be in there anyway

They could ask the guard how the Boston Red Sox are doing and when the guard says, "They won the World Series" they'll know that God is once again granting miracles and it's safe to announce they've all been in the room

The walls are soundproof but not smellproof, so when they get taken to the living room they can "fart" in the direction of the last cell on the way and when that guy smells 99 farts they are done

Or they could just tunnel out like in Shawshank Redemption, but they would need big posters and maybe some good rocks to polish

Title: Re: 100 prisoners & a light bulb (THE ANSWER)
Post by EB on Feb 20th, 2004, 10:37am
Though i have not read through everyones post. the answer in my mind is quite simple...after 100 days either every prisoner has been to the living room or not. The very first prisoner to enter the room turns the light off (if it isnt already). Everyone that enters the living room for the first time leaves the bulb as it is, without touching the bulb. If a prisoner enters a second time within a 100 day period, they turn it on. If at the end of 100 days the bulb is off, every prisoner has been in the living room only once. If the bulb is on, that means someone has visited twice, thus leaving a prisoner out of the equation...TA DA

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Feb 20th, 2004, 4:05pm
EB: your solution first appears (extended to repeat indefinitely) in the fifth post on the first page.

The current thrust of serious solution effort is going into a scheme based on the idea that a designated counter turns the light off at every opportunity, and everyone else turns the light on the first time they get the chance. The family of schemes has been formalised (by Rezyk) something like: each prisoner starts with an inventory. Each day, the light can carry a set package (varies between days), and the prisoner in the room can generate or discard certain items depending on his current inventory. When the prisoner enters the room each day: 1) if the light is on, he turns it off, and adds the previous day's package to his inventory; 2) he consults his current inventory to determine what items to create/destroy and whether to claim victory; 3) he decides, based on his new inventory, whether to turn the light on; 4) if he turns the light on, he removes the day's package from his inventory.

The current best solution (posted by Gypo) claims an expected time of just under 3500 days (around 9.5 years) and uses an initial 40-day stage to create and assign 10 badges and a crown (everyone starts with a token) before going through alternating stages of a) prisoners with badges try to collect single tokens up to 10 per badge (and those with no badge try to get rid of them) and b) the prisoner with a crown tries to collect tokens in 10s (each batch of 10 accompanied by a badge), while any prisoner with a badge and no crown tries to pass 10 tokens and a badge. The assignment of badges and crown works by generating a badge every four days (along with a crown the first day), and passing the badge and n(mod 4) tokens on day n until the day before the next badge is generated, or someone can't pass the required number of tokens - at which point, if the person didn't have a badge before, he keeps the badge and associated tokens, otherwise he passes the spare badge and the required number of tokens, generating token - antitoken pairs to make up the number (antitokens mutually annihilate with tokens given the chance - and they must get the chance in order for the prisoner's previous badge(s) to get passed). On the day the new badge gets created, if the previous badge is still unassigned, it and its tokens get picked up by that day's prisoner regardless of what he had previously. At least, I think that's how it's supposed to work... The subsequent stages were run for 2000 and 1500 days respectively the first time around, and then for 300 days each to try and pick up the stragglers. There is probably room for improvement there, if not in the initial badge/crown assignment process.

Other serious suggestions (that I can recall) are:

Each prisoner is assigned a day number (mod 100) and you leave/turn the light on on day n when you know that prisoner n has been in at some point. Sooner or later, someone will have found the light on on every day (mod 100) (except possibly the day following his own number) and know that everyone has been in. Refining this to assigning various sets of prisoners to various days and asserting that the entire set has been in has been proposed but not explored in much detail.

A generalisation that catches both the above and the token counting methods (but hasn't been suggested) is that of assigning a subset of the prisoners and a threshhold value to each day. If you know that at least as many of the day's subset as the day's threshhold value have been in, then turn/leave the light on, otherwise, turn/leave it off. By setting the threshhold to the size of the subset, you have the immediately above method; setting the subset to all 100 prisoners throughout gives the token counting method. The immediate drawback with a true hybrid method is that it becomes much harder to make explicit what each prisoner knows.

Finally, for completeness: run in cycles of 100 days, starting each cycle with the light on. Any prisoner who enters twice in a given cycle ensures the light is off when he leaves. If the light is on at the end of a cycle, then release is claimed. A trivial improvement is to start each new cycle on the last day of the previous cycle - using 100 day cycles, the bulb is meaningless to whoever goes in on day 101 - he already knows they failed, but it still doesn't come close to the naive token collecting method. Using this method for one cycle has been suggested as a means of dynamically assigning a counter for the token counting method, but it quickly became apparent that, although this uniquely offers a 100 day best case release time, it has a probability of working out to the best case less than one time in 1060 - to a very rough lower bound. Using a shorter selection period (first person in twice turns the light off and gets d tokens - at the end of the period, if the light's still on, the last person in accepts the n tokens accumulated) of around 30 days gives a shorter expected time, but still loses out to the various multi-stage methods. It might be worth taking the less than 100 day performance hit to try that, and then start a more conventional token collecting method, modified slightly to account for some tokens already being accumulated, on day 100, but that's a matter of collective preference for the prisoners, and if they were in a mood to gamble, then the optimum strategy is probably to wait 2 years then claim regardless...

Title: Re: 100 prisoners & a light bulb
Post by oddesyus (michael) on Apr 1st, 2004, 7:10pm
TEXT

When each prisoner enters the room with the light, he punches himself in the nose until it bleeds.  He then puts a single drop of blood on the lightbulb.  he does not repeat this if he goes in again.  When there are 99 drops of blood on the lightbulb, the prisoner that sees it can safely say that all the other prisoners have been in the room and they can all go to MENSA.

-- Oddesyus

Post by oddesyus (Michael) on Apr 1st, 2004, 7:33pm

This answer is acceptable because it is dependant on the state (of cleanliness) of the bulb.

A simpler, more cynical answer:  Select the biggest prisoner have him remove the lightbulb, break it to the point of sharpness and attack the guard in the dark.  Steal the guards keyes and free all the prisoners

:)

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Apr 2nd, 2004, 5:27am
A) How do you get 99 distinct spots on a lightbulb in the first place?

B) On Day 51, the prisoner enters to find a bulb with 99 distinct spots of blood...

C) On Day 51, the prisoner finds the bulb covered in insects...

Title: Re: 100 prisoners & a light bulb
Post by Oddesyus (michael) on Apr 2nd, 2004, 10:57am
first of all, a drop of blood is very small.  A prisoner can easily apply it with some hairs or a fingernail clipping

Where do you get 51 days?

It takes more than 51 days for 99 visits to occur

The bulb will not be covored in insects.  If all the rooms are perfectly sealed, there will be no way any bugs can get in.  Also the prisoner can bake the blood (so insects cnnot get at it) by turning on the light for a couple of seconds

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Apr 2nd, 2004, 3:23pm
There have been many far less painful means of leaving markers in the room suggested. How does this add anything that they don't have?

The comment in the header does not proclaim that marker solutions are invalid, just that they have already been discussed. So unless you have something truly original to offer (another means of leaving markers is not original), what is the point of repeating ideas someone else has already said?

What those tracking this thread are interested in is an improvement on the algorithms for handling the problem "in the box".

Title: Re: 100 prisoners & a light bulb
Post by Oddessyus (Michael) on Apr 3rd, 2004, 6:23pm
Well I guess that this riddle has already been slolved many times and nobody should bother writing in this thread any more and we should close the discussion

THIS IS THE END OF THE THREAD DO NOT ADD MORE BECAUSE YOU WILL BE SUPERFLUOUS FOR ALL ETERNTIRY
(or until you find something constructive to do)

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Apr 4th, 2004, 9:26am
Actually, I'd be very surprised if the current "best" solution turns out to actually be optimal. Any improvements are still welcome, and an optimality proof would be met with cries of rapture.

Title: Re: 100 prisoners & a light bulb
Post by Olly on Apr 19th, 2004, 7:11am

But, as they are allowed to meet each evening to formulate a plan, surely they just have to ask each other "Has anyone NOT been in the room yet?"

Once they establish that, then an assertion can be made.

Nothing to do with the light...

8)

Title: Re: 100 prisoners & a light bulb
Post by towr on Apr 19th, 2004, 7:28am

on 04/19/04 at 07:11:09, Olly wrote:
 But, as they are allowed to meet each evening to formulate a plan, surely they just have to ask each other "Has anyone NOT been in the room yet?"
They are allowed to meet up once, and that's also before the game begins..

Title: Re: 100 prisoners & a light bulb
Post by BNC on Apr 19th, 2004, 7:33am

on 04/19/04 at 07:11:09, Olly wrote:
 But, as they are allowed to meet each evening to formulate a plan, ...

They're only allowed to meet once before the whole procedure begins.

Title: Re: 100 prisoners & a light bulb
Post by alien on Apr 24th, 2004, 10:23am
if one of the prisoners was, say, 50 times consecutively in the central living room, no switching on-off of the bulb could transfere this fact to the next prisoner.  ???  :-/  :'(

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Apr 24th, 2004, 1:59pm
He doesn't need to communicate that he was there 50 times. Only that he was there at least once. Several workable approaches have been suggested in this thread. To start you off, I wll give the simplest (and also least efficient, with - if I recall correctly - a 270 year expected time before release).

This is called here the "Leader Solution": One guy is elected to be the leader. Only he can turn the light on. Everyone else turns the light off only the first time they see it on. Otherwise they leave it alone. When the leader has entered 99 times and found the light off (other than the first day, if he was the chosen prisoner), he announces that everyone has visited the room and they are all released: an amazing collection of 300 year old men kept alive by their own dogged determination!

If you read through the thread, you will find several really clever improvements on this, including one that gives an expected time until release of 11 years.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Apr 24th, 2004, 9:17pm
Checking the thread, a figure of ~10,000 days (~27 years) is mentioned (without proof) for the simple leader method.

I haven't bothered to check the entire thread properly, but a quick "Find" failed to turn up "270" being given as a number of years for any solution.

The current best solution claims an expected duration of around 9.5 years (based on simulations) has some scope for fine tuning (though probably still giving expectation around 9.5 years)

Title: Re: 100 prisoners & a light bulb
Post by alien on Apr 27th, 2004, 3:10am
I have a small improvement for the "Leader Solution" which speeds up twice the counting of the leader. The leader is elected not in the courtyard but after the whole procedure begins. Let me explain: the first two prisoners live the ligfht off. The 3rd prisoner toggles it on, and he is then the leader.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey2 on Apr 27th, 2004, 5:34am
The modification as you describe it won't work. If different prisoners enter on the first two days, then the prisoner entering on the third day is either the third prisoner to enter (and starts accumulation with a count of 3/100) or one of the first two repeating (and starts accumulation with a count of 2/100). If the same prisoner enters on all three days, things are still OK (start with 1/100) but if the same prisoner enters on each of the first two days but a second enters on the third, then he starts counting with a false count of 3/100...

The simple way to salvage this is to have the prisoner on the second day turn the light on if they are the first prisoner repeating. That way, whoever enters on the third day knows exactly what's going on. There are other possible schemes for selecting the leader dynamically, for example, the first person to enter the room for the second time during the first 30 days turns the bulb on and becomes leader, and no-one else does anything for the rest of the 30 days. On day 31, if the bulb is still off, the prisoner entering knows that 30 different prisoners entered the room in the first 30 days, and becomes leader. Anyone who entered the room during the first 30 days and found the bulb off knows they've been counted, while anyone who hasn't been counted turns the light off at the first opportunity after day 30 (and then counts as counted). If you read the thread, there are more complex methods suggested for schemes involving multiple leader types.

Title: Re: 100 prisoners & a light bulb
Post by alien on Apr 27th, 2004, 8:24am

Quote:
 at the end of the day the prisoner is returned to his cell.

Title: Re: 100 prisoners & a light bulb
Post by towr on Apr 27th, 2004, 8:45am
yes, so? He can still be brought back into the interogation room again the next day.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Apr 27th, 2004, 4:14pm
This is a step towards the "modified leader solution" (which can also be found in the thread). To go the rest of the way to it: How can you maximize the number of people who get counted before the leader is selected?

The modified leader solution is a large improvement on the leader solution, but better results are still possible.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Apr 27th, 2004, 5:19pm
Was there an attempt to solve this puzzle definitively for less than 100 prisoners? For 2 prisoners it is trivial (3 days average wait), for three - the 3-day dynamic leader selection  looks like the optimal solution ([approx] 9.167 days average wait according to my simulations); for four -  the 3-day dynamic selection works slightly better than the 4-day selection, giving [approx] 16.08 days, etc.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Apr 27th, 2004, 8:52pm
Several people discussed solutions for 2, 3, 4 prisoners on some of the earlier pages.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on May 1st, 2004, 7:52am
I have been considering this puzzle lately. The most successful schemes all work to set a particular person to know that everyone has been to the room. The big time killer for these schemes is that the messages must be delivered to this person, so you must wait for a long time for the conditions to be just right for him to receive them. The point of the token-based solutions is for others to assemble the individual messages into mass-messages that can be passed at one time. But still the situation must wait on the opertunity to deliver the right message to the right person.

I have been wondering if it might be possible to improve on this by allowing multiple copies of the messages to exist, and have multiple people able to recieve them, thus greatly increasing the odds of reception. To give an example, here is a scheme which suffers from the opposite problem as the token-based schemes do: it is extremely difficult to deliver the original message/tokens, so it is slow-starting, but once they are all delivered, should very quickly move to a win-condition. (I am not sure whether this has been suggested before or not. Clearly, it is very inefficient.)

Everyone maintains a list of numbers from 0 to 99, representing prisoners that are known to have visited the room. A the starting meeting they are each assigned a number, which is the only number in their list at that point. The days are counted modulo 100, and if they visit the room on a day matching a number in their list, they turn the light on (or leave it on). If they visit the room and find the light on, they add the number of the previous day to their list. As soon as some prisoner has all 100 numbers in his list, he declares everyone has visited.

The great flaw with this scheme is that it takes a long time for each person to publisize their own visits to the room, since they can only do so 1 time out of 100. But after a while knowledge of their visit disseminates throughout most of the prisoners, as everyone who knows of it repeats the message to someone else at every opportunity.

What I am wondering is if some version of this idea can be combined with a token-based scheme to improve times. With token-based schemes, only one copy of each token/badge/crown can exist, and the struggle is to pass those tokens to a single person. In the scheme above, every message (token) is duplicated instead of simply passed, and everyone collects them. Because messages are duplicated, each must be unique in content, so that the receiver knows whether or not this is a message he has received before.

Perhaps some mixture would help: a first stage wherein badges are created as outlined in the token-based schemes, but in the second stage, each badge is uniquely identified, and copied rather than passed. Everyone may collect them and the first to collect all of the badges declares freedom.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 1st, 2004, 2:36pm
Srowen suggested the method of labelling the prisoners from 1 to 100 and the light being on on day n+1 meaning that prisoner n(mod 100) is known (by the person in on day n) to have been in. If I've counted correctly, it's reply #28 (near the top of page 2). He reports a simulated expected escape time around 95,000 days.

In my post at the very bottom of page 9 I gave brief summaries of the categories of serious solution that have been proposed during the thread.

As far as I know (having just re-read most of the thread), no-one has seriously explored a more general information copying strategy.

Title: Re: 100 prisoners & a light bulb
Post by Paul Hammond on May 1st, 2004, 2:39pm

on 05/01/04 at 07:52:28, Icarus wrote:
 I am not sure whether this has been suggested before or not. Clearly, it is very inefficient.The great flaw with this scheme is that it takes a long time for each person to publisize their own visits to the room, since they can only do so 1 time out of 100. But after a while knowledge of their visit disseminates throughout most of the prisoners, as everyone who knows of it repeats the message to someone else at every opportunity.

That method was in fact proposed by S. Owen on page 2. He estimated that it would take 95,000 visits for 100 prisoners. It seems to me that you could improve the method's appallingly slow start as follows:

At first, proceed in periods of, say, 100 days (light is off at the start of each period). In period 0, if prisoner 0 visits he turns the light on, and then every subsequent visitor in the period knows that he has visited. Same for period 1, period 2 etc. After 100 periods, you reduce the period length substantially - perhaps even down to 1 day as in S. Owen's method.

Of course, 100 x 100 = 10,000, so the first phase alone would be no quicker than the best method found so far, but this speed-up technique might be useful in combination with the token-accumulation method, as you propose.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on May 1st, 2004, 8:14pm

on 05/01/04 at 14:36:44, rmsgrey wrote:
 As far as I know (having just re-read most of the thread), no-one has seriously explored a more general information copying strategy.

I, too, was rereading the thread, but had forgotten the details of Srowen's first solution while trying to comprehend all the later schemes. I knew the day labeling part came from some early proposal, but couldn't remember if "everybody collects" came with it. But indeed, the scheme I outlined is exactly Srowen's, and he deserves all due credit.

Paul - That is a definite improvement to Srowen's scheme. It might be interesting to see if maybe a shorter interval length could reduce the expected time of this approach to at least beat that of the single leader approach. Alas, I lack the programming capacities of other contributors.

Right now I am having a hard time thinking about these. This is why I decided to post now without trying to come up with a complete workable scheme.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 2nd, 2004, 6:13am
Intuitively (ie quite possibly completely wrong) having shorter cycles than 100 days (My feeling is 10-30 days) for the initial stages would be better. I've been meaning to pick up on programming again, so I might throw something together to get some actual data. I wouldn't hold your breath though...

Title: Re: 100 prisoners & a light bulb
Post by Paul Hammond on May 2nd, 2004, 7:21am
I guessed at 100-day initial cycles because a quick calculation suggests that it takes 69 days for there to be a better-than-even chance of that cycle's prisoner having entered the room. 30 days only gives a 0.26 probability. But maybe repeating shorter cycles would be better than my cautious 100 days?

Title: Re: 100 prisoners & a light bulb
Post by Rezyk on May 2nd, 2004, 9:08pm
Consider also adopting dynamic label assignments -- "Each prisoner starts with no label.  Within the first period for label X, the first prisoner who enters with no label adopts label X."

This should vastly improve the productivity of all periods.  Even up through the 80th period, each period is more likely than not to have the bulb on and information passed from the 3rd day onwards.  You can also throw in a small accumulation jumpstart with this (analagous to Salem's leader selection) for further optimization.

Of course, there is the downside that you must account for the case of some prisoners never acquiring a label.  For this, I think a "designated reset day" or perhaps a combination with token gathering would be well worthwhile.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 4th, 2004, 8:56am
Well, the results of computer simulation of the basic named-prisoner per period are in - running 100 days per period clocks in around 54,000 days for release (averaged over up to 10,000 runs). Any number of days per period from about 40 or so on up to something like 150 is still within 1% of that figure but 70 days per period seems to be marginally ahead (out of 10, 30, 40, 50, 60, 70, 80, 100, 120, 150 and 200).

Trying a two stage process, running for one great cycle (100 periods to get back to the original prisoner) of long period and then short periods thereafter, seems to knock around 1000 days off the expected time for cycles of length 200-400 followed by cycles of length 30-70. Simulations on small prisoner numbers (around 6-10) suggest that this improvement is accompanied by a much lower variance in release time.

Having developed my intuition further by simulating some 6 prisoner cases by hand, for large cycle times, the advantage lies in wasting fewer days waiting for someone to show up who can turn the light on - the disadvantage comes in having to wait much longer to spread information about a given prisoner if you miss out during a given great cycle. During the first great cycle, long periods are beneficial, but in subsequent cycles you generally want to spend as little time as possible waiting for a given prisoner to become active...

I've yet to try Icarus' badge-sharing suggestion or Rezyk's dynamic labelling (which I really should have thought of myself...).

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 10th, 2004, 4:41am
Real life has prevented my making much progress, but looking at Rezyk's dynamic allocation system from a theoretical perspective: calculating the number of days required to give a 99% or better chance of allocation in each cycle gives values less than 100 up to about 90 assignments. The accumulated total by then is around 500 850 days. On the other hand, if there are 90 people out of the hundred, each known to have visited by the same number of people independently, you need each to be known by about 95 people to get the expected number of people knowing about all 90 up to one...

It looks very much like dynamic allocation gains relatively little - only thousands of days, not the tens of thousands needed to get into contention.

[e]Checked my figures overnight... I really should check my facts before I post :-[/e]

Title: Re: 100 prisoners & a light bulb
Post by Icarus on May 10th, 2004, 3:47pm
I've been too spaced out by a nasty cold to look into it much either, but all indications point to my bright idea being unfortunately rather dull.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 11th, 2004, 3:33am
I wouldn't give up all hope just yet - The badge sharing approach only needs 10 cycles per great cycle, and quick calculations show that if 75 prisoners share each badge independently, you expect around 6 (5904900/1048576) prisoners to have a complete set. Using gypo's stage 0, the badges are allocated in such a way that they can have a numbering assigned in advance, or you can adopt a dynamic badge-numbering system (first unnumbered full badge in during a cycle adopts that number. If the light remains off at the end of a cycle, the person in on the first day of the next cycle becomes responsible for collecting an anonymous badge later and numbering it for the missed cycle. After the numbering cycles, you have a stage where any unnumbered full badges are transmitted and collected by whoever wants a badge to number. On the first pass, you may want to skip this stage, and insert it after a repeated stage one (assuming that the reason no-one got 10 badges is that one or more aren't yet full). Once I figure out the numbers to get a good chance of 75 people sharing a given badge, I might run some simulations. If anyone else wants to try first, feel free.

OK, looking back at the stage timings for gypo's solution, there's a ball park of 1500 days for badge collection, meaning 150 days per cycle for the simple version, giving an expected number of prisoners sharing each badge around 35 (by some pretty wild estimation rather than sober calculation or simulation) giving between .15 and .2 expected prisoners sharing all ten badges...

Thinking around the problem a bit more, is a {10,10} solution optimal for a badge sharing second stage? If you have only 9, or even 8 badges (of two different types to account for 100 not dividing evenly), that will knock a cycle off the sharing stage (where you're not concerned about which type a badge is, only that it's full), and reduce the required length of each cycle (you need rather fewer prisoners sharing each badge to get the same expected number knowing all of them)

For that matter, with a dynamic badge assignment, and the associated higher starting counts for badge-holders, is it worth increasing the number of badges to 11 or 12?

Hopefully these questions may help open up the topic for further investigation, even if they don't lead anywhere in themselves...

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 1st, 2004, 1:53pm
I have read all posts and have run simulations of my own employing a strategy similar to the labelling concept suggested recently.  Information transfer can take two forms:

1.  The number of counted prisoners
2.  A list of the prisoners who have visited.

In the the case of #1, only one prisoner at a time may hold information about another prisoner to avoid redundancy.  In the case of #2, anyone may carry information about anyone else.

#1 has the advantage that information doesn't have to be too specific - the result is simply true (everyone's been there) or false (not everyone has been there).  #2 is beneficial because it allows the first prisoner with all the information to request freedom at their first opportunity.

I read all the posts today for the first time - stupid, considering I could have benefitted from some of the work already done here - and approached the Method #2 slightly differently from S. Owen, and later Icarus, did.  My first approach was to divide days into sets of 5 and assign a sequential number to each set.  So days 0 through 4 would be set 0, days 5 through 9 would be set 1, etc.  If any prisoner with Label X enters the room during Set X, he switches the light on.  Any prisoner who enters the room after him but still within set X, adds X to his list of known prisoners.  On the first day of every set, the prisoner entering the room, records Prisoner X on his list and switches the light off (unless of course he is Prisoner (X+1)).  Any prisoner with information may impersonate prisoners whose numbers they have collected.  For example:

P5 enters the room on day 16.
16 / 5 = 3 rem 1.
3 <> 5 so light remains off

P3 enters the room on day 17
17 / 5 = 3 rem 2
3 = 3 so light goes on

P41 enters the room on day 18
light is on so records "3"
light stays on

P59 enters the room on day 19
light is on so records "3"
light stays on

P7 enters the room on day 20
light is on so records "3"
light goes off (new set)

After 500 days, the sets start again from 0 but this time with P41, P59 and P7 able to represent P3 if they visit the room during set 3.

this yielded a result of about 50000 days.  Not good enough.  So I adopted a strategy for dynamically adjusting the duration of a set to allow more receivers to get a message and to allow a larger window per cycle for a given prisoner to visit the room during his set (with set = 5 days, odds are 5%).  After some critical amount of knowledge is moving among the prisoner, the set duration can be reduced.  This implies starting with larger sets in the beginning at the expense of considerable initial lag time but good recovery from the dynamic reduction of set duration.  It turns out that as you increase the initial set duration value and reduce it over time, the principles cancel each other out and produce the same result - about 50000 days.  It doesn't matter if the set duration follows a decaying exponential or a linear drop - the results are the same - EXCEPT of course where set duration approaches 1.

I am currently working on a new solution that achieves results in the region of about 10000 days - it employs a similar principle to that mentioned above combined with a suggestion made earlier with the trading of tokens.  I will let you know how it goes.  I think there's plenty of room for optimization.

If anyone is interested in the code for my initial testing, I'd be happy to share.

One other thing bothers me though:  Read the next post.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 1st, 2004, 2:15pm
Someone mentioned earlier in one of the posts that the initial state of the switch was relevant.  I may have misinterpreted it but would like to point out that it is irrelevant because it can simply be set to whatever the first prisoner in deems appropriate.

However, another poster mentioned a similar problem posted on the IBM site.  And Mr Wu who obviously followed the link quoted it by saying it might have originated in Hungary.

No one else responded to this post but I found it quite interesting.  If the solution to this problem is as it is given on the IBM site, then it appears we are asymptotically approaching an optimimum with no hope of a revelation because the solution on the IBM site is trivial and was mentioned on the first page of this post.  I have no complaint however, because I enjoy the challenge, but it's interesting to note the the IBM solution is the simplest of all the solutions mentioned here (the leader solution) - except for the creative and annoying leaving of markers or beating up the guards.  For those of you who are interested the URL is :

http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/solutions/July2002.html

The key difference in this puzzle is that there are two switches, and every prisoner must toggle at least one switch.  It turns out that this is the same as there being one switch with no such requirement.  Also the IBM riddle clearly states that the interval between visits is not fixed which eliminates the possibility for synchronising information with days since the meeting.

Thus this thread has become a quest much like that to prove that the earth was not flat.  I am hoping the quest continues as the does the Olympic 100 meter sprint to the extent that we're ultimately looking to shave off individual days from our iterative average.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 2nd, 2004, 7:08am
Hey Guys,

Me again.  I know everyone has lost interest in this problem and decided that AlexH's optimization is as good as it gets.  Well I don't believe we have reached an optimum solution yet.  I cut 2000 days off my 10000 day solution which uses information transfer in packets and dynamic counters (anyone can be a counter and can pass on his accumulation of counts at any time).  My current average is 8700 days.  But I have only just started work on this solution and am certain that is far from being optimised.  Anyone who is interested in helping me continue in the direction I'm going, please let me know and I'll give you my source code.

Here is a description of the solution as I have it right now:

Let Prisoners P each begin with a token count of 1, which I will represent like this :  Pi[1] where i is the prisoner label or number.

The principle involves the trading of tokens via a register (the light switch).  The number of tokens stored in a register is a function of the number of days since the meeting - this function has huge potential for optimisation.  Currently the value (v) of a token is:

v(d) = 2 ^ [(d/c) % (floor(log Pn / log 2) + 1)]

where d is the number of days since the meeting, c is the period during which tokens have a particular value, Pn is the total number of prisoners.  The log part of this function is actually log Pn with a base of 2, but without subscripts, I thought I'd be safe and express it this way.

The following policies are used to determine if tokens should be transferred or not:

1.  A prisoner must collect tokens if it is the first day of a new cycle (ie. the first day of a new token value).  This rule beats all other rules.  Once the prisoner has collected the token from the previous cycle, he may commit to the register a token with the current token value according to the remaining rules.

2. A prisoner must commit a token to the register if his current balance is less than twice the current token value (assuming of course that he has a token of the current value).

3.  A prisoner may not collect tokens if his balance is less than the current token value.

An example:  (let R be the register such that R[4] represents Register balance of 4)

R[0];      // register is empty
c = 3;      // cycle period is 3 days
Pn = 4;   // number of prisoners is 4
V = 0      // current token value

d = 0;      // day 0
V = 2 ^ 0 = 1;
P2[1] -> P2[0];
R[0] -> R[1];

d = 1;
V = 2 ^ 0 = 1;
P0[1] -> P0[2];
R[1] -> R[0];

d = 2;
V = 2 ^ 0 = 1;
P2[0] -> P2[0];
R[0] -> R[0];

d = 3;
V = 2 ^ 1 = 2;
P1[1] -> P1[1];
R[0] -> R[0];

d = 4;
V = 2 ^ 1 = 2;
P3[1] -> P3[1];
R[0] -> R[0];

d = 5;
V = 2 ^ 1 = 2;
P0[2] -> P0[0];
R[0] -> R[2];

d = 6;
V = 2 ^ 0 = 1;
P3[1] -> P3[3];
R[2] -> R[0];

d = 7;
V = 2 ^ 0 = 1;
P2[0] -> P2[0];
R[0] -> R[0];

d = 8;
V = 2 ^ 0 = 1;
P1[1] -> P1[0];
R[0] -> R[1];

d = 9;
V = 2 ^ 1 = 2;
P3[3] -> P3[4];
R[1] -> R[0];

end;

As I said before - there are optimisations that can be made and all are welcome.  My only regret is that unlike my original strategy which involved the spread of information, I'm disappointed that the current count can't be shared among the prisoners because of redundancy.  There may be a hybrid which incorporates certain prisoners keeping track of particular prisoners while other prisoner(s) keep count.  But probably not.  Let me know your thoughts.

Title: Re: 100 prisoners & a light bulb
Post by SWF on Jul 2nd, 2004, 7:02pm
I know how you feel about working on this alone- it always seems that only one person at a time cares about this problem. That is the way it was when I worked on this (and several of the other hard problems too).

I think the current best is Rezyk's method of around 3531 days, near the bottom of page 8.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 3rd, 2004, 12:50pm
SWF:  I think I will beat that.  I'm currently running at about 3700 - but I can make some optimizations I think.  I will let you know how I do.

Matt.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Jul 3rd, 2004, 6:10pm
I think you can simplify the reasoning by separating what the prisonner sees on arrival and the state he leaves on leaving.  You shouldn't think of the 4 cases (switch on, switch off, leave on, leave off).  Just think of what happens from one day to the other.

Leaving the light on on day d is a message from one prisonner to the next one.  Since the sender doesn't know who the receiver is and the receiver might be there for the first time, the meaning of the light on day d must be the same whoever sent it and whatever happened before.

In our case, leaving the light on means "I am giving you k token" where k is a function of n.  For example, your v(d).  Whoever sees the light on counts in the v(d-1) tokens and then decides to send or not send v(d) token, which might be the same value.

In the leader method, v(d) is always 1 and anybody who is not the leader will give away whatever token he has one by one.  You don't wonder if you switched it on before or not.  Just count any token in and leave the light on if you have any token to get rid off.

In the other method of trying to combine 2^k groups, then v(d) is always some 2^k, and the prisonner should send that value if that value can be send without breaking a bigger group.

In any case, an optimization is that when starting the whole process, the first values v(d) could be 1, 2, 3, 4, up to some value to be defined, considering that at that time, it is likely that prisonners are there for the first time, so you can "snowball" a few points until it becomes too likely that a prisonner returns.

If you add the 28 extra token to be distributed to get a nice 128 total, then you can give it to the first prisonner, and v(d) would then start with 29, 30, 31, ...

But maybe, instead of giving 28 token to the same person, it is better to distribute them in order to form bigger 2^k groups.
If you give all the 28 the token to the 1st person, you have 4 prisonners with 29, 1, 1, 1 token.  That is 7 groups of 2^k (16+8+4+1, 1, 1, 1), while the arrangement (16, 8, 4, 4) has only 4 groups, which is a few steps forwards in the work of combining 2^k groups.  Then of course, we need to figure how it combines with the inital 1, 2, 3, ... points.

OK, no solution, just some thoughts.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Jul 3rd, 2004, 6:20pm
PS: it is still interesting to have long runs of same token count values so that if a prisonner receives a 2^k group and it does not combine with one he has, or if he simply has none, he can immediately send it to the next prisonner, while if the token value changes too often, people might be stuck with a 2^k group he can not send further, and it might take a few days until a prisonner happens to have the right group available to be sent.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 3rd, 2004, 8:55pm
Hey Grimbal,

Thanks for the input.  Actually - I had already done something similar to your suggestion.  Since my last post with the example, I have made some optimizations which brought my number of 8700 days down to about 3700.

My approach thus far has been driven by trying to pass more than one bit of information at a time - initally by passing known prisoner labels around and relying knowledge propogation to get the message to everyone.  But this has a disadvantage in that it still requires specific prisoners to be in the room at least once during a specific 10 day period every thousand days, for example, which is a tall order.

The new plan was to stay with knowledge propogation but to transfer less specific transaction between any (or almost any) two prisoners at any time.  You are correct that having decently long enough periods during which transactions involving the same token value may take place is beneficial; mainly because it prevents non perfect powers of 2 from ending up in the hands of a single prisoner.

But getting back to your suggestions.  What I changed in my approach was to give 4 tokens to the first prisoner in the period when token value is 4, 8 tokens to the first prisoner in the 8-token period, and 16 tokens to the first prisoner in the 16 token period.  That allows these prisoners to trade tokens from day one which is an advantage.  I also introduced the policiy you suggested which is:  Don't trade tokens if you have zero tokens or if you have a token balance which doesn't equal the current token value.

What I have done now is to optimise the process is to choose value periods according to the number of expected prisoners with a token balance greater than zero who will need to trade in that period.  For example during the first period, all 100 prisoners will need to be involved in a transaction (just one).  During the second period, 50 prisoners will need to trade, during the third period 26 (with the extra 4 tokens to the first prisoner in that period), during the fourth period 14 (with the extra 8 tokens), in the fifth period 8 prisoners (with the extra 16 tokens), in the sixth round 4 prisoners and in the last round 2 prisoners.  For each of these I calculated the average time needed for the required number of prisoners to transact at least once and used those numbers to choose my period lengths.  I will submit the numbers in a few minutes as a separate post - I'm on the wrong machine right now.

Anyway, my current number is 3700 and I'm about to get to some optimizing.  Once again, thanks for the input.  It's always welcome.

Matt.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 3rd, 2004, 10:17pm
Okay these are my numbers for the cycles:

680 days for trading token value 1
610 days for trading token value 2
545 days for trading token value 4
485 days for trading token value 8
425 days for trading token value 16
360 days for trading token value 32
290 days for trading token value 64

These numbers were chosen in the following way:

Ultimately, I was looking for a number which would, on average, give the prisoners a 50% chance of freedom from the first great cycle.  This means that the probabilities associated with each round have to yield a combined probability of 50% for the great cycle.

In other words, if the probability of completing each round without stragglers, is 89% (which it is) then in six cycles, the probability of success in the first round is (0.89 ^ 6) = 50%.

In 680 days, the prisoners have an 89% chance of completing all value 1 trading.  In 610 days, the 50 remaining prisoners have an 89% chance of completing the round, etc.

This means that 50% of the time, the prisoners escape in under 3400 days, but the other 50% of the time they will not.  If they are not successful in the first round, the second round adds substantial time onto the back which pushes the average time up.  My results look something like this:
3352
2944
3323
5929 (this bastard affects my beautiful average so far)
3172
3098
6345 (and again)
2982
6083 (yet again)

These are numbers from a real sample I just ran.  If you ignore all the high numbers, the low numbers are quite nice.  So I'm looking for input again -  I want to know how to change the strategy to minimize the second great cycle.  I could increase the probability of success in the first round which can help to bring down the average, but that means adding more days to the first great cycle which would make it very difficult to compete with Ryzek's solution.    The alternative is to establish a means for quickly picking up the stragglers in the second cycle.  The first cycle, if it is not successful, is usually distributed in the following way (for example):

1 x 64
2 x 32

or

1 x 127
1 x 1

or
2 x 64

It's usually one transaction short of success and that can mean another 3000 days.  I know there's a short cut to picking up the pieces but I wouldn't mind some input.

Matt.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 4th, 2004, 7:33am
Okay I found a mistake in my numbers.  I am working with 7 cycles and I used probabilities based on 6 cycles.  Each cycle therefore needs a 91% chance of success in order for the great cycle to be successful 52% of the time.  The new numbers are therefore:

700 for cycle 1
630 for cycle 2
565 for cycle 3
500 for cycle 4
445 for cycle 5
380 for cycle 6
310 for cycle 7
(rounded to the nearest 5)

This increases the great cycle to 3530 which is very sad because this is higher than the current minimum.  It might be worthwhile to give the first great cycle a better chance of success at the expense of days upfront in order to bring the average down.  I should also note that results within a successful first great cycle will range between 3220 and 3530 whose average (3375) is still better than 3400 - but again, only if the first great cycle succeeds.  hmm.

Perhaps I should rewind a little bit and choose a very slightly different approach.

Matt.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Jul 6th, 2004, 4:54am
If I remember correctly, somewhere in the first few pages of this thread were some posts analysing the best sizes of chunks to divide the counts into - I believe the conclusion was that the optimum was about equal between 10 groups of 10 (or 8 of 11 and 1 of 12) and a three stage 20 groups of 5 going to 4 of 25.

If you use fewer stages, then you can accept lower probabilities of success in each, which makes them more efficient for a given net probability.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 6th, 2004, 8:51am
Rms:  It depends on the desired outcome.  For example, if you're looking for 50 transactions in the first round, you will need a certain number of days to be able to expect a 91% chance of getting all 50.  In this case it's about 700 days for 50 transactions (of the type that my solution uses).  However, if you're looking for transactions such as those described in earlier solutions (and posts), then the optimal number for the first round will be different.  Previous solutions made use of assigned counters who counted to 9, for example, and then provided complete counts to a master counter.  My solution works differently - it has 50 dynamically assigned counters counting to 2 in the first round.  The number of days required to achieve these two different outcomes will be different.  Ultimately the solutions boil down to a similar number of total days - mine requiring higher numbers in the first great cycle (which is my current issue) while previous solutions had less stringent requirements, being able to fall back on subsequent great cycles and still achieve a result in reasonable time.  I think the key to this problem - regardless of the method, is choosing the right numbers for the job - not as a general set, but as a specific group of numbers finely tuned to the specific solution which uses them.

Matt.

Title: Re: 100 prisoners & a light bulb
Post by Bitrot on Jul 20th, 2004, 3:15pm
What is wrong with my reasoning?

[A] Each prisoner can learn exactly 1 bit of information each time he is selected.

[B] The knowledge that everyone has been selected constitutes N bits of information.

[C] Each prisoner is selected on average once every N days.

[D] Therefore, at least N*N days are required, on average, before any prisoner can know that all prisoners have been selected.

[E] Therefore, no algorithm can have an average running time that is faster than O(n^2).

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Jul 20th, 2004, 3:28pm

on 07/20/04 at 15:15:46, Bitrot wrote:
 What is wrong with my reasoning?[A] Each prisoner can learn exactly 1 bit of information each time he is selected.

This is wrong. The amount of information can vary depending on the number of day a prisoner is selected.

Quote:
 [B] The knowledge that everyone has visited constitutes N bits of information.[C] Each prisoner is selected on average once every N days.[D] Therefore, at least N*N days are required, on average, before any prisoner can know that all prisoners have been selected.[E] Therefore, no algorithm can have an average running time that is faster than O(n^2).

The O is right, but we're into reducing the constant in front of n2 now.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 20th, 2004, 5:27pm

Quote:
 What is wrong with my reasoning? [A] Each prisoner can learn exactly 1 bit of information each time he is selected.

Also, it is true that one bit of information is available to any prisoner who enters the switch room - but knowing how to interpret the information is another story.  Receiving the bit of info is easy - translating it into something meaningful is the key.

Title: Re: 100 prisoners & a light bulb
Post by Bitrot on Jul 20th, 2004, 8:14pm

on 07/20/04 at 15:28:42, Leonid Broukhis wrote:
 This is wrong. The amount of information can vary depending on the number of day a prisoner is selected.

It's either on or off. That's one bit, regardless of when.

Quote:
 The O is right, but we're into reducing the constant in front of n2 now.

Ok, but I still haven't convinced myself that's it's possible to do with constant <1. I realize of course that it has been proven possible, by construction, many times over in this thread. But it seems like I have to read all 11 pages with all the theorizing, dead ends, and abortions therein, or else I won't understand the latest posts, which all rely on previously created vocabulary.

So: is there some simple method that will work every time and averages <10000 days for N=100 that you could explain to me?

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Jul 20th, 2004, 8:35pm

on 07/20/04 at 20:14:22, Bitrot wrote:
 It's either on or off. That's one bit, regardless of when.

To quote a joke without naming hair color of the characters:

- What is the probability that you will encounder a dinosaur in a convenience store?
- 50%. Either I will, or I won't.

You see, the amount of information depends not only on the number of possible states of a signal, but on the distribution of probabilities of such states as well. If, e.g. an algorithm requires to leave the light on on day 2 if the person visiting on tday 2 was not the one who visited on day 1, then whoever comes in on day 3 does not get much information from the light that is on, because it is to be expected with 99% probability. If the light is off, however, he gets -log2(1/100) = more that 6.5 bits of information.

Quote:
 So: is there some simple method that will work every time and averages <10000 days for N=100 that you could explain to me?

See a post by Rezyk on Oct. 14, 2003. Is it simple enough?

Title: Re: 100 prisoners & a light bulb
Post by Bitrot on Jul 20th, 2004, 8:47pm

on 07/20/04 at 20:35:36, Leonid Broukhis wrote:
 To quote a joke without naming hair color of the characters:- What is the probability that you will encounder a dinosaur in a convenience store?- 50%. Either I will, or I won't.You see, the amount of information depends not only on the number of possible states of a signal, but on the distribution of probabilities of such states as well. If, e.g. an algorithm requires to leave the light on on day 2 if the person visiting on tday 2 was not the one who visited on day 1, then whoever comes in on day 3 does not get much information from the light that is on, because it is to be expected with 99% probability. If the light is off, however, he gets -log2(1/100) = more that 6.5 bits of information.

Sure, but since we're talking about the average running time, we can't look at what will happen in 1% of the cases. Is it not true that the expected amount of information is limited to 1 bit?

Quote:
 See a post by Rezyk on Oct. 14, 2003. Is it simple enough?

I'll check it out before I go on arguing when I know I'm wrong. :) Thanks.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jul 21st, 2004, 5:46am
Bitrot, Let me sum up my method:  There are 100 prisoners so essentially 100 bits of information need to be communicated.  If all 100 prisoners had to receive all the information I doubt it could be achieved in less than O(N^2).  But because the responsiblity of counting the prisoners visits is ultimately left to one person, the O is reduced.

This reduction is possible with a form of compression.  Initially, in the first phase, information is passed (rather sub-optimally) one bit at a time.  But in the second phase - in less time than the first phase took - information is communicated two bits at a time; and then four bits at a time in the even shorter fourth phase and so on.

My solution calls these transfers "transactions" and the expected number of transactions in my solution is O(N) - 50 + 26 + 14 + 8 + 4 + 2 + 1 = 105 (for 100 prisoners).  The extra 5 is due to adjustments for non-powers-of-two.

All that the solution requires is that the order of prisoner visits is favourable for these transactions to take place - and it turns out - in my solution - that the mean is about 2900 visits with a 6000 spike every now and then which pulls the average up to 3400 visits which is comparable to the other solutions mentioned (although with different distributions, I think).

Title: Re: 100 prisoners & a light bulb
Post by Anonymous Coward on Jul 23rd, 2004, 3:27pm

on 07/20/04 at 15:15:46, Bitrot wrote:
 What is wrong with my reasoning?[B] The knowledge that everyone has been selected constitutes N bits of information.

Wouldn't one bit be enough to convey that information? It depends what the bits mean. Anyway, it is not necessary to know which prisoners have visited, just how many.

Title: Re: 100 prisoners & a light bulb
Post by LaneMac on Sep 24th, 2004, 11:06pm
Gonna try to keep it simple optimization is for others.

Im a prisoner what do i know?

1) How many times ive been in the room
2) When in the room: If the light is on or off

I need something else so i assume
3) I know what the cumulative days are

Have i been in the room in the last 10 days?
If Yes turn light off and go back to my cell.
If No continue questions.

If the light is on i ask the question:
Have i been in the room MORE times than the value of the ones place of the cumulative days in prison? (0-9) (0=10)

If the answer is yes and the day value is (0). I will call that everyone has been in the room.

If the answer is yes and it is day (1-9) I leave the light on and go back to my cell.

If the light is off I ask the question:
Is it day (1)?

If No then leave light off and go back to my cell.

Have i been in the room more than one time?
If No leave light off and go back to my cell.
If Yes turn light on and go back to my cell.

At worst case you have a series of prisoners that have been in the room 2,3,4,5,6,7,8,9,10,11 times. I haven't worked the probabilities and don't know if i could but in a truly random environment I dont see how this wouldnt be worth the risk.

I believe this is the simplest solution. Other rules will improve assurance but will increase the overall time in prison.

Title: Re: 100 prisoners & a light bulb
Post by Van Luong Nguyen on Oct 3rd, 2004, 8:33am
I believe this solution workx to end up eventually with one prisoner knowing FOR CERTAIN that everyone has been to the living room.  Any flaw or error in my thinking?  (I did not yet try to estimate the "average" time to get there using my solution, nor to prove that it is optimal or close to optimal).
SOLUTION:  Designate only one unique prisoner X who is allowed to turn the light OFF.  X always turns the light OFF before leaving the living room.  Each of  the other 99 prisoners, say A, can never turn OFF a light he finds ON, and can turn ON the light only ONCE, and that is on the FIRST time A finds the light OFF when visiting the living room.  Because only X is allowed to turn the light OFF, all prisoners other than X who visit the living room after A has turned it on will leave the light unchanged (ON) until X eventually visits the living room and turns the light OFF.  Because each of the 99 prisoners other than X will therefore turn the light on exactly ONCE (the FIRST time he finds the light OFF), which will be seen as ON eventually by X, when X has found the light ON 99 times, he will know FOR CERTAIN that everyone has been to the living room.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Oct 3rd, 2004, 9:30am
Yes, it is called the leader solution, given by Caveman (24. Jul 2002 at 09:14).

But it takes an average of 27 years to complete.

We are searching for a way to improve on it, there seem to be solutions that work in 11 or 9.5 years on average.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Oct 8th, 2004, 8:53pm
For Josh English - I have removed your poll because your proffered solution (everyone can see the bulb and count toggles) has been discussed in the first page or two. At that time, William clarified that the intent is the light is NOT visible from any cell. The only way the prisoners are allowed to communicate with each other is by whether or not they leave the light on when they exit.

As has been mentioned before, there are plenty of "outside the box" solutions. But they are as un-interesting as they are plentiful. What has made this puzzle attract so much attention, and kept people interested in following it, is finding the best "inside the box" solution. This is the challenge.

Title: Re: 100 prisoners & a light bulb
Post by brightguy on Oct 16th, 2004, 10:39pm
Hello everyone... I just stumbled onto this site and got caught up reading the riddle with the pages of proposed solutions.  I've read about 10 pages worth, so I am familar with what has already been proposed.

I want to state first off that I use "brightguy" because I'm a lighting designer - not because I think I'm bright.

I want to throw something out there and see if anyone else can do the math.  I'll admit that I sucked at all the math courses I took in college (and I have an engineering degree).

The "Leader Theory" sounds logical.  BUT, I would think there is one key thing everyone is missing that would maybe cut some time out of this...

In the initial meeting, everyone gets together.  Therefore, they can break into 2 groups - MEN and WOMEN.  The riddle does say "he or she".

That may not help at all, but I don't think I've read any mention of this.  It is too late for me to try to work details, but for some reason I feel like using this male/female ratio could help.

Title: Re: 100 prisoners & a light bulb
Post by brightguy on Oct 16th, 2004, 11:08pm
I'm not claiming that would help.  But after reading some of the other methods, my intuition tells me that adding the sex ratio into the equation might help narrow it down.

During the initial meeting they create groups (lets say there are 50 men & 50 women), they assign a male & female leader & they create rules, and for each rule they set a # of days to abide by it before moving to the next rule:

GROUP:  men vs. women
RULE:  If you are a MAN, leave the light ON; if you are a WOMAN, leave the light OFF
DURATION:  100 days

GROUP:  MEN w/ first names starting w/ A-M vs. everyone else
RULE:  If your a man w/ first name from A-M, leave the light ON; otherwise, leave the light OFF
DURATION: 50 days

(other rules would be similar but change the sex and alternate A-n or M-Z)

GROUP: men with first name A-N who've been in the room before vs. everyone else.
RULE:  If you've been in the room before and your a guy and you first name is between A-N, leave the light on; otherwise, leave the light OFF.

... and so forth.

I KNOW there is probably more to it than that, but my thinking is that during the initial meeting, the group could determine several ways to break into smaller "trait" groups... whether it is eye color, hair color, sex, name....  and these traits could be implemented into a cycled set of rules to narrow down the field.  Of course, I am assuming that these people have memory retention and math skills.

Sorry, I just thought I would throw in my 2 cents.  I'll be having constant thoughts of this riddle now that I've stumbled across it.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Oct 18th, 2004, 6:29am
You don't need to pick existing physical characteristics to group the prisoners by - you can give each one a unique number from 1 to 100 (or 0 to 99 if you prefer) and then group numbers together however you choose. The problem comes when you try and get useful information out of such a scheme - for instance, if odd numbers (men) turn the light on and even numbers (women) turn it off for the first 100 days, then each person going in knows the parity (gender) of the previous person to go in, but has no idea whether that person has been in before, etc. So on day 101, you have up to 100 prisoners who know up to 2 pieces of information - that at least one odd or at least one even person has been in, or possibly that at least one of each have been in.

Since there's no way to tell which odd-number turned the light on, or which person will find it on, there's no obvious way to turn what information you do get into something useful.

Title: Re: 100 prisoners & a light bulb
Post by Angler on Oct 21st, 2004, 1:36pm
Grr... just lost the whole thing which I typed.

Here's the gist:

This is likely to be a solution nobody has thought of before.  And it is a sick - albeit fast one.  Don't read until you are prepared.

[hide]You need the prisoner to be able to count to 100 as well as being really brave (or stupid).

Whenever a prisoner enters the living room, if that is before the 100th day from the first day of imprisonment, he or she commits suicide on that day.

Since the warden will (obviously) not choose a dead person, a new prisoner will be picked each day until Day 100 when there is only one left.  The said prisoner can safely say that everyone has entered the living room.[/hide]

My kudos to this problem (http://www.ocf.berkeley.edu/~wwu/riddles/medium.shtml#brownEyesRedEyes) for giving me the inspiration.
For questions that may be asked:

1. This puzzle only requires you to get someone out as fast as possible.  It demands no further conditions.
2. Think this is impossible?  Read some news on Middle East and think again.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Oct 21st, 2004, 7:29pm
William had someone send that "solution" to him in a private e-mail,  inventively suggesting ways the prisoners can kill themselves. However, when you suggest the idea in that planning meeting, don't be suprised when your fellow inmates decide to change it to a "99 prisoners & a light bulb" problem right there, thus saving you the need for such inventiveness. :D

Title: Re: 100 prisoners & a light bulb
Post by gary84 on Oct 23rd, 2004, 8:52pm

I think "equally randomly" means that every prisoner has been in the room exactly once before any prisoner is selected for the second time. In that case the solution is as follows:

1.  if this is the first time you have ever entered in the room and the light is off, turn it on.
2.  if this is the first time you have ever entered in the room and the light is on, leave it on.
3.  if this is the second time you have ever entered the room and the light is on, turn it off.
4.  if this is the second time you have ever entered the room and the light is off, announce everyone has been in the room.

Done.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Oct 24th, 2004, 4:11am
If I roll an ordinary die, each number, from 1 to 6 comes up equally at random. If I roll the die 6 times and get a different number each time, I get suspicious - the probability of such a thing happening is 5/324 or a little over 1.5%. By the time you have 100 possible outcomes, the chance of getting all 100 in the first100 trials is less than the chance of Earth being hit by an extinction- level meteorite during the time it takes you to read this post...

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Oct 24th, 2004, 2:15pm

on 10/23/04 at 20:52:13, gary84 wrote:
 I think "equally randomly" means that every prisoner has been in the room exactly once before any prisoner is selected for the second time. In that case the solution is as follows:

In that case, after 100 days everybody can cheerfully announce it is time to go home.  Or, if the days are not counted, the first who enters the room for a second time can call for the liberation.

Title: Re: 100 prisoners & a light bulb
Post by ed on Oct 26th, 2004, 5:04pm

I don't think the problem can be solved in a reasonable
amount of time, because if the
person say in cell 66 never reports no one would ever
know. At the very least it would require cell 66 to be
called multiple times or during a pre-determined time
which could take years.

We should probably start concentrating on a proof that
the problem cannot be solved in a given amount of time.

What is the minimum amount of information required to
determine that  100 inmates have visited and how much
information is transferred and retained with each 1/0 visit
to the main room.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Oct 26th, 2004, 5:41pm
It is true that there is no guarantee that the prisoners will ever get free. Since the prisoners are chosen at random, it is possible (vanishingly small, but still possible) that some prisoner never gets chosen. In this case, it would not matter what scheme the prisoners concoct.

This is why all of the various schemes offered here are given in terms of their expected release time - the average time it takes for release to occur. And for that, the current fastest method gives a time of about 9 years (if I remember correctly). Not great, but not that unreasonable either.

Title: Re: 100 prisoners & a light bulb
Post by jordan on Oct 29th, 2004, 5:22pm
My solution requires a few things to happen:
1. the bulb in the room cools down very slowly
2. there is a clock in the room
3. the prisoners have a thermometer or perfect temperature sensitivity

Let's say at room temperature, when the bulb is off, it is at 65 degrees F. If the bulb is turned on for one minute at the end of the day, it cools down to one degree warmer at the beginning of the next. ex. 1 min on - 66 degrees, 17 min on - 82 degrees.

When the first prisoner comes in he turns the bulb on for one minute at the end of the day and then turns it off. At the beginning of the next day, the next prisoner comes in and takes the temp. reading of the bulb. At the end of the day, he turns the bulb on for one more minute, and then off again. If the prisoner has already come in once, he simply turns the bulb on for the same amount of time as the prisoner before him. When a prisoner comes in and sees that the bulb is at 165 degrees, he will know that all the prisoners have been there, and will tell the guard, and be free to go.

Title: Re: 100 prisoners & a light bulb
Post by Three Hands on Oct 30th, 2004, 5:37am
Unfortunately, the sadistic guards have a habit of keeping the lightbulb on overnight, and then putting the bulb to the appropriate state of how the prisoners left it the next morning (after all, they do need somewhere to play poker...)

Hence, when the prisoner comes in to find a bulb at 200F the next morning, he's left somewhat confused.

And all this without knowing the potential problem of exponential heat loss (which I think is the case, but I'm not an expert on thermodynamics...)

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Oct 30th, 2004, 12:57pm
Besides, there's no clock in the room. And, yes, the temperature will tend to suffer exponential decay with the bulb off.

If the bulb were perfectly insulated (not even radiating heat), then you'd still have the problem of judging the temperature - apart from lacking a thermometer, the prisoners also have the problem of getting to the perfectly insulated bulb to measure it...

And when the bulb blows and gets replaced, the prisoners are completely stuck...

Title: Re: 100 prisoners & a light bulb
Post by Vicktor on Nov 3rd, 2004, 1:28pm
Maybe something like this would work :

Each prisoner has to keep in mind a counter, starting at 1. Let s call this counter "C".
When entering the bulb room, here is the rule they must follow :
1) "Did i enter the bulb room yesterday ?"
if yes, dont do anything
if no, go to 2
2)
"Is the light bulb ON ?"
if yes, add 1 to my C counter ( C = C + 1 )
if no, C is constant
"Is it the first time i enter the bulb room ?"
if yes, ensure the light bulb is turned ON
if no, ensure the light bulb is turned OFF

If at any time, C = 100, we re free ...

Title: Re: 100 prisoners & a light bulb
Post by mattian on Nov 3rd, 2004, 1:40pm
Sorry Vicktor - No dice.

It's highly unlikely that C will ever reach 100.  According to your solution - each prisoner may switch the light on only once - but this result will be observed by any one of the remaining 99 prisoners.  The count will increment as you describe, but it will be distributed among the prisoners will not be available to one discrete prisoner who can make the declaration for freedom.

Title: Re: 100 prisoners & a light bulb
Post by Brad711 on Dec 10th, 2004, 8:13pm
I"m not a genius, but I think I heard this riddle once.  I think maybe it had something to do with the fact that a light bulb heats up...  I dono, but maybe you could keep the light bulb on until it burns out...  You could alaways shatter the light bulb...  or just make up some code system to scratch onto something...  Just Ideas.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Dec 11th, 2004, 8:34am

Title: Re: 100 prisoners & a light bulb
Post by Brad711 on Dec 11th, 2004, 8:39am
I was thinking... Does the problem have to give a 100% chance of living?  If not, there are plenty of shorter solutions that give a 95% chance or so.  Anyway, what if there are 4 or 5 leaders, and all of them turn off the light when it is on, just like the leader solution.  Exept for that either once it has been off 40 times or so, he or she announces.  Or when there are like 3 times in a row where one person has been in(at least 50 days or so apart for each time) and the light is off.  I dono, just suggestions.  Someone do the math on  the 5 leaders thing for the length of time and the probability of dying.  Please.

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Icarus on Dec 11th, 2004, 9:09am
This post is found on the first page:

on 07/23/02 at 23:33:37, Ivo wrote:
 Hm, well, a few people have suggested solutions that'll take significantly longer than the prisoners' life spans to work...  However, the best one I can come up with is "Wait 3 years and assume (with 99.5% accuracy) that everyone's been in the room"....  Anyone got a better solution?

But the classic interpretation of the puzzle is that only 100% certainty is acceptable. Think of the prisoners as being immortal unless killed. Then even the slightest chance of being executed does not make sense.

Title: Re: 100 prisoners & a light bulb
Post by Rezyk on Dec 11th, 2004, 7:12pm
I suggest this modification to the problem:

The warden will listen in on all the planning and, if possible, pick an ordering that will result in a false assertion.  Otherwise he uses random selection.

Title: Re: 100 prisoners & a light bulb
Post by Mattis on Dec 20th, 2004, 4:11am

on 12/11/04 at 19:12:34, Rezyk wrote:
 I suggest this modification to the problem:The warden will listen in on all the planning and, if possible, pick an ordering that will result in a false assertion.  Otherwise he uses random selection.

I think the rule above gives a fun twist to it if you still allow solutions that don't have a 100% chance of success. In that case you must make an elaborate plan that the warden will listen to. You then follow the plan for say three years, and then you claim your freedom (none of the other prisoners will know about your plan though).

The scary thing here is that every other prisoner may reason the same way: "I make up an elaborate plan and play along for X years/months/weeks, and then I take a chance". So, if any of the other prisoners is a stone-cold gambler you might all be free or dead after say 200 days.

I liked the thinking about parity-checking suggested long ago, where each prisoner toggled the lightswitch the first time around. After say two years, if the ligh is toggled off, you can be pretty darn sure that everyone has been there, since the odds that there are two prisoners would have never been in the room is really small.

Maybe, if you were to be the one to lay out the plan you could suggest a plan that sounds like a reasonable and 100% bulletproof plan, but in secret the plan would in fact give you something like parity-checking or something else that gives you higher chance of successfully claiming freedom when you visit the room after say three years or so.

(I know the discussion has come to discuss the real failsafe solutions with only 1 bit of information passed each day, but I thought that lying to the warden and your fellow prisoners was fun enough to motivate a post of my own).

Title: Re: 100 prisoners & a light bulb
Post by Patashu on Dec 21st, 2004, 1:46am
I've been wondering something. What if the light bulb had three states? How much quicker could you guarantee the escape of all prisoners with a three-state bulb? How about four? Five? Six?

Title: Re: 100 prisoners & a light bulb
Post by Mattis on Dec 21st, 2004, 11:06am
Actually, the more I think about it, the better the solution where you take a chance after three years is. If everyone has been to the mainroom, then fine, you are all free.

But, if there are prisoners who haven't, there are two possibilities:

Either you have had a stroke of bad luck. You should have used the badges and crown-system maybe.

But more likely, if there are prisoners who in three years have never been picked,  the warden is being a bitch. Maybe he will never take some of the prisoners to the light-room. Maybe you are all just part of his twisted little game.

If that is the case, no badges or crowns in the world will save you, you are doomed to rot in this wicked place.

Title: Re: 100 prisoners & a light bulb
Post by Reege Lafai on Jan 3rd, 2005, 2:23pm
Hi, this is my first time to the forums and I am impressed! So many smart people!

I have an idea. Perhaps this solution will work, perhaps not. In any case, I thought that the people here could build off of this and see what you come up with.
The average lifespan of a lightbulb is 1500 hours. Divide that by 100 people and you get 150 hours per person.
Each time a prisoneer is in the room, he/she turns the light on, regardless of whether or not they have been in the main room before.
Each prisoneer keeps track of the amount of time the lightbulb is left on in their pressence. Once a prisoneer has left the lightbulb on for a total of 150 hours, they turn it off and don't turn it on again, even if they are shown to the main room after that.
In this way, once every prisoneer has used up their 150 hours, (thereby also having visited the main room,) the lightbulb will burn out and the prisoneer on whose "shift" the lightbulb burns out will know that everyone has been in the main room.

Holes in this solution:
1. How would the prisoneers keep track of exactly 150 hours? The solution requires that the prisoneers know how long they are in the main room.

2. What if the lightbulb is slightly more or less than average in its lifespan? That could mess things up a bit. Here is a modified solution if the lightbulb is special (not average):

To account for the fact that the lightbulb may be more than average, that is lasting for longer than 1500 hours, each prisoneer should leave the lightbulb on for 151 hours. This would add 100 hours to the initial time the lightbulb is planned to be left on, and the 100 hours would eat into the time of the last prisoneer's time to leave the lightbulb on. However, it would still go off sometime during his "shift" so it would still work.

To account for the fact that the lightbulb may be less than average and burn out earlier than 1500 hours, the prisoneer on whose shift the lightbulb burns out should not assert that all the prisoneers have been in the main room. The prisoneer after him/her should, upon realizing that the lightbulb has burned out, wait until just before he/she gets put back into their cell and then assert that every prisoneer has been in the main room. This part of my solution I have not thought through as thoroughly. Does anyone see any problems with it that I've overlooked?

The minimum amount of time it would take for this solution to work is slightly more than two years. Of course, the maximum amount of time can never really be computed because of the randomness factor: there could always be one prisoneer left out of the random cycle, sitting in his/her cell waiting to use their 150 hours. I think this randomness factor is what has been messing up all the other solutions from achieving an optimal answer. Even if my solution doesn't work, it would be mighty helpful if someone were to figure out a way to get around this factor.

If this solution works, many thanks to my two brothers who discussed this with me and helped me divise a solution. =)

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jan 3rd, 2005, 2:37pm
What if the light bulb is on when the first prisoner enters the room on the first day?  He might wonder how long it has been on.

Let me put it this way - I would not want to be a prisoner relying on this solution.  But an interesting idea, nevertheless.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Jan 3rd, 2005, 4:58pm
You're not the first to suggest this approach, though you have taken it farther than before. The problem of the light bulb not being nice and giving up at exactly 1500 hours (each prisoner should leave it on for 15 hours, by the way, not 150) is much larger than you figure, though. In addition to mattian's point that the bulb may not be at the beginning of its life, the variance in light bulbs is almost certainly too great for this to work with any reliability. Even with 150 hours, so each person could have it on an extra hour, there is a good chance the light bulb would still not burn out, and then everyone is left sitting in a dark room, without ever having the chance to deduce everyone has been there.

on 01/03/05 at 14:23:42, Reege Lafai wrote:
 To account for the fact that the lightbulb may be less than average and burn out earlier than 1500 hours, the prisoneer on whose shift the lightbulb burns out should not assert that all the prisoneers have been in the main room. The prisoneer after him/her should, upon realizing that the lightbulb has burned out, wait until just before he/she gets put back into their cell and then assert that every prisoneer has been in the main room. This part of my solution I have not thought through as thoroughly. Does anyone see any problems with it that I've overlooked?

How would this help at all? What is the point of sitting around in the dark room for a while before making the announcement? The same people will have visited the room at the beginning of this visit as at the end, so why wait? And the only advantage of having the first person to enter the room with a burnt-out light announce, rather than the one it burnt out on, is the very slim possibility that the one extra guy happens to be the sole person who hasn't visited before.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Jan 3rd, 2005, 5:05pm
Another problem is that it is not only the burning, but also the turning on and off that uses up the bulb.  And to check wether the bulb is burned out, you have to try it.  So you are using up the bulb even if one prisonner is unlucky enough to remain in his cell.

Title: Re: 100 prisoners & a light bulb
Post by Reege Lafai's brother on Jan 3rd, 2005, 6:02pm

on 12/21/04 at 01:46:52, Patashu wrote:
 I've been wondering something. What if the light bulb had three states? How much quicker could you guarantee the escape of all prisoners with a three-state bulb? How about four? Five? Six?

Actually, the bulb has 4 states (unless it is too high to reach): On, off, Screwed in, and Unscrewed.

This led me to thinking, if the bulb can be reached, what about each prisoner unscrewing it 1/100 of the way out the first time (and only the first time) they get into the room? The prisoner that finally unscrews the light bulb demands their freedom.

In response to the problem with our (My sister's and mine) solution about the light bulb not being at full capacity on day 1, the first prisoner could turn (and leave) the light on. No one touches the light switch until the light bulb burns out. When they replace it (and this they must do), you are left with a brand new light bulb with which to start your strategy.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jan 4th, 2005, 7:11am
There is only one logical interface which has only two states - on and off.  As indicated in the red text at the top of this puzzle, no interpretation other than these two states may be obtained from the bulb/switch combination in the room, thus excluding the option of screwing and unscrewing the bulb, making marks on the wall or filling the room with sand and making snow angels.  Just a switch - on or off.  That's all.  After all, this is a logical puzzle and there aren't really any prisoners out there waiting for the solution.  As long as we're hypothesising, therefore, we may as well pretend the prisoners are unable to perform any function other than walking, toggling the switch and pondering.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jan 4th, 2005, 7:18am

on 01/03/05 at 18:02:42, Reege Lafai's brother wrote:
 Actually, the bulb has 4 states (unless it is too high to reach): On, off, Screwed in, and Unscrewed.

Not true.  Even if we allowed physical states of the bulb (as opposed to logical states), these would only be three.

On, off and unscrewed.  Screwed in is a superset of on and off unless by "screwed in" you mean without making electrical contact.

But if we're unscrewing the bulb anyway, why not place it in significant positions about the room and leave in a 150 days?

This is precisely why we limit the puzzle to purely logical solutions including ideal bulbs and switches.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Jan 4th, 2005, 8:13am

on 01/03/05 at 18:02:42, Reege Lafai's brother wrote:
 In response to the problem with our (My sister's and mine) solution about the light bulb not being at full capacity on day 1, the first prisoner could turn (and leave) the light on. No one touches the light switch until the light bulb burns out. When they replace it (and this they must do), you are left with a brand new light bulb with which to start your strategy.

The problem with this fix is that you only know the bulb's been burned out and replaced when it burns out while a prisoner is in the room (to be able to use this method, the bulb has to be left on while burning the first one, and left off between visits while burning the second)

Besides, what stops the warden from replacing the bulb with the one he's been using in the guard room, and using the new bulb himself? Or, for that matter, changing the bulb from time to time himself...

The only guarantee we have is that the switch will be in the same on/off state when the next prisoner enters as when the previous prisoner left - for all we know, the entire room is dismantled and replaced overnight...

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Jan 4th, 2005, 5:45pm
Besides which, only one prisoner can know that the old bulb has burnt out, and so must have been replaced. The other 99 would not know it was time to put this plan in action.

The idea of working off bulb life, while interesting, is critically dependent on the prisoners knowing to a very high degree of accuracy the lifetime of the bulb at the start. It is very unlikely they would have this knowledge.

I think, if I were to restate the problem, I would despose of the whole room & light bulb, and just have a guard visit a prisoner every day, deliver a message of "yes" or "no" from the previous prisoner, and take down this prisoner's own "yes" or "no" answer, to give to the next guy. This would preclude anything other than the 1-bit transfer (assuming an unbribable guard).

Title: Re: 100 prisoners & a light bulb
Post by Mattis on Jan 5th, 2005, 4:47am
Even if lightbulbs had a very reliable lifespan, there is another problem with the lightbulb-lifespan-strategy:

Sure, the warden, and the whole prison-system seems wicked and evil. But that don't mean that they don't take their environmental responsibility.

It would be a nasty surprise to agree on the lifespan-strategy only to find on the first day that the prison uses low-energy long-life-lightbulbs that lasts 10 times longer than ordinary bulbs. ;)

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Jan 5th, 2005, 6:41am

on 01/04/05 at 17:45:44, Icarus wrote:
 Besides which, only one prisoner can know that the old bulb has burnt out, and so must have been replaced. The other 99 would not know it was time to put this plan in action.

I started out assuming this, then realised that, in order to control the burn time, the individual prisoners would have to leave the bulb off between visits once the strategy started, while, during the initial burn, it makes some sense to leave the light on permanently (or spend your time in the room flipping the switch), which allows a simple signal to be sent (if the light's on we haven't started yet...)

Title: Re: 100 prisoners & a light bulb
Post by Reege Lafai on Jan 5th, 2005, 1:32pm
Yeah, you guys had good responses. I knew there were flaws in the special-lightbulb theory.
But like I said before, I don't think this will ever be solved because of the randomness factor.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Jan 5th, 2005, 5:19pm
Several solutions have already been discovered. None of the solutions guarantee the prisoners with release because this cannot be guaranteed: it is possible that the warden's random picks will never happen to pick one of the prisoners. What is desired is a scheme such that, if it does lead one of the prisoners to make a declaration, that declaration will be sucessful. The second desire is to find a scheme that will on average produce a positive result in the least amount of time.

Plenty of solutions meeting the first criteria have been proposed. The simplest is the "Leader" proposal. The prisoners pick one guy to be leader at their meeting. Only the leader is allowed to turn off the light. Everyone else turns it on the first time only that they enter the room with it off, but otherwise never touches it. The 99th time the leader turns off the light, he can safely declare that everyone has been to the room. The problem with this method is that it takes a considerable amount of time to work (I don't remember how long - a variation that speeds things up significantly, and which was William's answer when he first posted the problem, takes 27 years on average).

Several other solutions have been mentioned. Most of them variations on the general "leader" concept. The fastest make use of a concept of "tokens" collected by subleaders and past on to the leader. Currently the best scheme has a average run-time of about 9 years.

So the basic problem is solved. It is the optimization problem that remains open. And you are correct that it will remain that way, though not because of randomness. Rather, because it is extremely difficult to prove that no better scheme exists.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Jan 6th, 2005, 7:19am
I've been thinking about this problem again and I am beginning to take issue with the manner in which optimum strategies are determined.  I don't think average escape time is a sufficient measure of the success of a given strategy.

For example:

Suppose two strategies are run 10 times and the results are:

Strategy 1:

6345; 6443; 5987; 6302; 1995; 6744; 6229; 6221; 5883; 2013
AVG: 5416.2

Strategy 2:

5437; 5498; 5972; 5164; 5375; 5248; 5335; 5657; 5634; 5043
AVG: 5436.3

Strategy 1 has the better average but Strategy 2 is more stable.

I encountered this problem in my implementation of the token solution which produced extremely low numbers (under 2000) about 1 in 5 iterations, but higher numbers (above 6000) for the others.  Clearly, the strategy favours certain patterns in the sequence which relies on probability.  So there is a 1 in 5 chance that this strategy, for example, will flatten the other strategies, but a 4 in 5 chance that it will not do as well.

So how should the success of a given strategy be measured?

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Jan 6th, 2005, 7:55am
The expected time to release isn't a bad measure - if a million prisons all ran this experiment, and all the prisoners used the same strategy (or the 100 prisoners had to earn their escape a million times in a row) then they should use the strategy with the least expected time to release.

If you are prepared to gamble on a relatively slim chance of an early release, then minimising expected log release time would probably be better.

In general, you probably want to minimise the expected value of some function of release-time.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Jan 6th, 2005, 8:35am
That makes sense.

Doing one more year of prison is more painful when you did just one year than when you did 10.  So there should be some decrease in the penalty of an additional day of prison when you average.

Some people might like taking risks.  They'd prefer to have a slight chance for a very early escape, even if it means a longer average time.  Some might be overcautious.  They'd prefer to minimize the chances of a long stay, even if it means no chance for an early liberation.

Then there might be reasons they want to be free at some specific date and not at others.  They might want to spend christmas outside, but if they miss christmas, they'd rather spend the winter in prison, where they have shelter.

All this amounts to what rmsgrey said: "In general, you probably want to minimise the expected value of some function of release-time." the function being the dissatisfaction for some liberation date.

Now, just to complicate the problem, each prisonner might have a different opinions about what is the objective.  It should be fun to see all the prisonners arguing and negociating to settle to a solution that suits everybody enough so that nobody will want to sabotage it.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Jan 6th, 2005, 5:48pm

on 01/06/05 at 07:19:37, mattian wrote:
 So how should the success of a given strategy be measured?

It does not make sense to average the release times because the prisoners only need to escape once and they do not care about the repeat performance of a strategy. The median or some other agreed upon percentile is a better measure in this case: what really matters is odds of escaping after so many days.

To give a better example of misappication of average:

A patient asks the doctor: What are my options?
Doctor: The average lifespan without the operation is 1.5 years, with the operation - 4 years and counting.
Patient: Great, I'll have the operation! By the way, what are the median lifespans?
Doctor: Well, without the operation it's slightly less than 1.5 years, and among those 10 people who had the operation the only person who survived it 40 years ago still lives, so the median must be 0.

Title: Re: 100 prisoners & a light bulb
Post by towr on Jan 7th, 2005, 12:52am
It's a matter of opinion whether that's a misapplication of statistic measures.
A utilitarian might simply go for the best expected outcome (average). Whereas an overly risk averse person might go for the best worst-case.

What the best measure is for a strategy for this problem depends on how the prisoners feel about it. If they feel 9 years is only twice as bad as 3, and 16 twice as bad as 4, then a logarithmic scale of 'cost' might work best.
But they might also just feel very strongly about getting out in the weeks before christmas, and care much less for the rest of the year.
Or maybe they just want to be free before they die.

Title: Re: 100 prisoners & a light bulb
Post by riadov on Feb 17th, 2005, 5:11pm
hi i am new here
after hours of reading 22 pages i think i know what the problem's are(your's i mean)

1)u didnt read well the riddle  ???
2)u have concentrated on meaningless words in the riddle  ???
3)u see numbers and u start calculating  ???

some of u thought of having the meeting in the central living room ,well of course its wrong :THE PRISONERS CANT CHOOSE.
well let us say there is  a tunel X that gides from A to B(and it's the only way),if i want to get from A to B the only way is thru X 8) i am not joking here

let :
-X be the central living room
-A the cells
-B the meeting place or home sweet home

soooooo to be in the cell:  THE PRISONERS HAVE TO PASS THRU THE CENTRAL LIVING ROOM and to get out from the cell to go to the gym toilet or wherever the meeting is THEY ALSO HAVE TO PASS THRU THE CENTRAL LIVING ROOM (its not the Disney Land out there)

so the first prisonner to be chosen will claim that all the prisoners were in the central living room :the day they entered their cells or the day they went to the meeting

P.S: if i am wrong ,don't be rude to me ;)

Title: Re: 100 prisoners & a light bulb
Post by mattian on Feb 18th, 2005, 5:26am
CONGRATULATIONS!!!  Hey everyone, Riadov has solved the riddle - why didn't we think of this?  There we were, silly us, trying to do calculations *spit* while the answer was staring us in the face.  In fact, why do we bother to think at all?  I mean the whole point in life is apparently to find short cuts rather than solve problems (whether it is the correct means or not).  Apparently the people who subscribe to this forum are interested only in thinking and problem solving - how very short-sighted of them - instead of just knowing the answer or finding a spelling error that makes the question null and void.  I didn't realise until now how much easier it is to solve riddles by technicality - or even better, by introducing factors which help solve it.  For example, the solution to this particular riddle is actually "one day", because all the prisoners actually had a key to their cells and their cell doors opened up directly into their living rooms at home, so the solution is this:  they turn the key, open the door and walk into their living rooms.  The solution is so simple - I battle to figure out why all of you waist so much time thinking!  In fact, why not extend this principle into all things - in a game of chess, for example, my pawn needs to be diagonally adjacent to a piece belonging to the opposition in order to take it - however, with this incredibly ingenious new way of thinking, I've just realised, that there is no need for this at all; the opponent's piece can simply be taken at any time - my pawn (or any piece for that matter) need not even be there, since the act of picking up the opponent's piece and removing it such a trivial task requiring very little energy and absolutely no thought.  From now on, when I play chess, I will simply take my opponent's pieces willy-nilly whenever I feel like it.  Or move my pawns backwards, or throw the board in the air while making gurgling noises.  This concept of protocol and good spirit is becoming an annoyance and I feel liberated now that I've come to realise that it is so unnecessary - I will make up my own rules, stand on my colleague's heads to get to the top, take the shortest path to every outcome because my name is SOCIETY_IN_THE_21ST_CENTURY!

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Feb 18th, 2005, 8:14am

on 02/18/05 at 05:26:28, mattian wrote:
 my name is SOCIETY_IN_THE_21ST_CENTURY!

My name is "good-old-days"

What? this isn't the Sandman Duel thread?

Well, the prisoners is obvious - it must be 100 days because the warden has to pick a different prisoner each day, so 100 days will have them all visiting.

What? What happens on day 101? They're all at home by then...

Besides, the tally marks on the wall will solve it!

Or they remove the bulb and use the socket to electrocute themselves! Whoever's left alive on day 100 knows they're the last prisoner!

Or stage a revolt! Kill the warden and take over the prison!

******************************

As for tuning for reaching a given probability of escape as early as possible, my understanding is that existing multi-stage methods already do something similar - the end of each stage of the first full cycle is designed as a trade off between taking longer to get to the release stage, and risking having to do a second full cycle. Depending on the threshhold probability, they're probably already fairly close to optimum evaluated that way too.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Feb 18th, 2005, 3:26pm
Now, play nice! riadov has misunderstood the point of this puzzle, though I do wonder why he didn't pick it up after reading all the previous posts, since it has been explained before.

riadov - finding a way of interpreting the puzzle so that the prisoners can get out easily is NOT the point here. Those sorts of puzzles are found in the "What Happened?" forum. In the Hard forum are, preferably, puzzles that do not depend on tricky wording, but rather deep and imaginative thought to come up with a solution. (Maintaining this standard is hard, because people tend to assume that if they don't know the answer, it must be hard - so a lot of people keep posting trivial puzzles that they are hung up on.)

The point of this puzzle is to figure out the best scheme the prisoners can use when:
1) the only time anyone gets to enter the room is during their visit.
2) the only way a prisoner has to communicate any message to another prisoner is by leaving the light on, or leaving it off: one bit only, and only readable by the randomly selected prisoner of the next day.

This is the real challenge, and as an intriquing challenge it beats the pants off of coming up with different interpretations.

Title: Re: 100 prisoners & a light bulb
Post by riadov on Feb 18th, 2005, 6:47pm
hey ICARUS u are the polite person here,10x  ::) ::) :) :)
btw MATTIAN try to speak 5 languages FLUENTLY (and i mean it:russian, english, french, arabic and arabic lebanese slang language);in addition that english isn't my native language(i said DON'T BE RUUUUDDDDEEE if i was wrong ;that means IF I MISUNDERSTOOD)
:-X :-X :-Xthink of that ;) and try to puzzle it or to make several forms of equations perhapse...I don't know...Oh yeah !!!! play chess with it :P

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Feb 18th, 2005, 7:19pm
Sorry, riadov, but you accidently set off something that has caused a lot of frustration. Many people are interested in this thread, and whenever they see a new post, they like to check it to see if someone has found an interesting new approach to this problem.

But far more often, it has been someone who did not bother to read even the first two or three pages, and posts a solution of "break the bulb" or "leave marks on the wall", or some other variation, without noting that this has been suggested many, many times before. There is nothing wrong with such solutions. The thing is, that is not what we find intriguing about this problem, so such solutions are just a nuisance.

Your suggestion is different from the "marker" solutions, but still bypasses why the problem is interesting to us, so all the frustration we feel tends to boil out. Still, patience is always the wiser course.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Feb 20th, 2005, 8:32am

Don't take my post the wrong way - As Icarus pointed out, you were something of a scapegoat for my response to the abundance of posts in this - the forum's flagship thread - which trivialize the puzzle.  It is the longest thread because it has inherent intrigue due to the fact that there is no definitive answer, and no way of telling whether the current solution is in fact optimimum.  It mirrors scientific development in which a good theory is said to be one which survives for a long time before it is disproven.  In this thread, the best solution is about 3000 days and will remain so until it is less than that.

Also, it's very seldom that I can lash out at society and your post provided the trigger for me to do so.  I think that has something to do with the fact that you did say you'd read all 22 pages, and having done so, I thought you might have noticed the building frustration with posters who attempted to solve the problem by technicality.  This is a common post by newcomers except that they tend not to claim that they've read all the posts.

And finally, I've been slammed in this forum before as well - I tried to take it personally for a while, until I realised it wasn't intended that way.  In my experience with this forum so far, vandalism is essentially non-existent and subscribers are here for one reason only - to solve problems because their jobs are boring, or whatever.  My post was not so much a stab at you as it was a commentary on the lunacy which is our current society - call it a rant if you will.

Keep puzzling.  And congrats on the languages - I know a number of cretins who don't speak any - a bit of English here and there, perhaps.

Title: Re: 100 prisoners & a light bulb
Post by riadov on Feb 20th, 2005, 11:47am
no problem man i must excuse myself ,anyway i am working at the riddle but no progress so far  :-[hope to helpful next time ;) ;D

Title: Re: 100 prisoners & a light bulb
Post by Worcester on Mar 6th, 2005, 9:29am
Hi, I've read through this thread, and i don't understand AlexH's process that he describes on page 4, and offers another explanation on page 5 for. Could someone explain it in English, (not in code), to someone with a reasonable, but not Undergraduate, knowledge of mathematics.

Thanks to anybody who does this.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 6th, 2005, 3:06pm
Here is how I interpret AlexH's scheme (a variation of Paul Hammond's).

The prisoners decide in the advance meeting to break the coming days into a repeating set of 7 "stages" (7 stages for any number of prisoners from 65 to 128 - more generally, it needs to be the exponent of the least power of 2 >= the number of prisoners). If stage 7 ends without release, a new repetition of stage 1 starts, and so on. Each stage lasts a number of days decided on at the meeting, so everyone knows when the stages begin and end.

Consider the prisoners to have counts based on "tokens". There are 7 types of tokens (one for each stage), which I will call 1-tokens, 2-tokens, 3-tokens, etc. A prisoner with 2 1-tokens combines them to form a 2-token. 2 2-tokens combine to form a 3-token, etc. Each prisoner is given a single 1-token to start with, except that 28 additional 1-token are given to one or more prisoners so that the total starting 1-tokens is 128 (least power of 2 >= # of prisoners). Those prisoners receiving the extra tokens combine them to form higher order tokens as possible. No prisoner will ever have more than one token of a given type.

On a day of stage k, a prisoner can only turn on the light if he has a k-token. This represents leaving his k-token in the room for someone else to pick up.

A prisoner can pick up the token (i.e., turn off the light) in either of two circumstances: (1) he already has a k-token, in which case he combines the new one with his current to create a (k+1)-token. (If he also already has a (k+1)-token, he combines again to create a (k+2)-token, and so on.) Or (2) it is the last day of the stage, in which case he picks up the token to hold until the next stage k.

Eventually, all the 1-tokens are paired off to create 2-tokens, which are then paired off to create 3-tokens, etc, until finally the two 7-tokens are combined to create a single 8-token. The prisoner doing this announces that everyone has visited the room.

Title: Re: 100 prisoners & a light bulb
Post by JayL on Mar 14th, 2005, 10:02pm
Hi, I believe I have a way of being certain that all 100 prisoners have visited the living room. The one flaw is that it takes a long time which, according to note 1, is fine.

I sincerely hope that no one has posted this solution before.

1. One person is choosen as the leader.
2. The light, which is initially off, is left off until the leader has come into the room for the first time. The leader then turns it on.
3. When someone visits the room they would notice that the light has been turned on.
4. The person then turns the light off and leaves.
5. When others, not including the leader, enter the room they are to leave the light off and not turn it on.
6. Once it is the leader's turn to enter the room again he notes that the light, which he originally turned on, has been turned off.
7. He now knows that 2 people, for sure, have been in the room. Himself and the person who turned the light off.
8. The leader then turns the light back on and leaves.
9. When others, who have not gone into the room before, enter they turn the light, if it is on, off. If the light is already off then they leave it the way it is and pretend that they have not visited the room yet.
10. When the leader comes in he can infer that 3 people have truly been to the room. He turns the light on and leaves.
11. This process continues, until every prisoner, with the exception of the leader has not only visited the room, but has turned the light off.
12. Once the leader sees that the light, that he turned on, has been turned off 99 times he can safety say that everyone have been to the room.

BTW if you have turned the light off before, you obviously don't turn it off again.

Could someone please calculate the average number of days this would take.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Mar 15th, 2005, 12:41am
Damn!  How come we did not think of that?  ::)

This, in essence, was proposed in the 11th post on the 1st page.  The average time of this solution is 27 years, and was given in the last post of the 1st page.

Title: Re: 100 prisoners & a light bulb
Post by JayL on Mar 15th, 2005, 12:27pm
Are you allowed to do anything else while in the room. It doesn't really say in the question. For example if you can loosen the light bulb or entirely unscrew it instead of just flicking the light on and off. If you have more options the first, second, ...etc new person, that goes into the room can each do a certain thing untop of w/e was done before. Therefore you can reduce the time by half.

Title: Re: 100 prisoners & a light bulb
Post by riadov on Mar 15th, 2005, 12:46pm

on 03/15/05 at 12:27:34, JayL wrote:
 Are you allowed to do anything else while in the room. It doesn't really say in the question. For example if you can loosen the light bulb or entirely unscrew it instead of just flicking the light on and off. If you have more options the first, second, ...etc new person, that goes into the room can each do a certain thing untop of w/e was done before. Therefore you can reduce the time by half.

man i have learned my lesson 8) when u read well and i mean WELL the replys ,try to find out a solution that no  one proposed

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 15th, 2005, 12:49pm
HA HA HA HA  !!!!   ;D

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 15th, 2005, 2:17pm

on 03/06/05 at 15:06:49, Icarus wrote:
 A prisoner can pick up the token (i.e., turn off the light) in either of two circumstances: (1) he already has a k-token, in which case he combines the new one with his current to create a (k+1)-token. (If he also already has a (k+1)-token, he combines again to create a (k+2)-token, and so on.)

No, a k token and a k+1 token does not make a k+2 token. If a holder of a k+1 token picks a k token, a deadlock is possible.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Mar 15th, 2005, 2:45pm
One optimization that seems to be missing in the solution where token of 1, 2, 4, 8 etc are combined into a single 128-token:  Instead of giving the extra 28 token to one person, spread them to have 1x16, 1x8, 2x4 and 96x1 token.
this reduces down to 100 the number of groups to be combined.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Mar 15th, 2005, 3:04pm

on 03/15/05 at 14:17:23, Leonid Broukhis wrote:
 No, a k token and a k+1 token does not make a k+2 token. If a holder of a k+1 token picks a k token, a deadlock is possible.

But if you already have a k-token and a (k+1)-token, then picking up an additional k-token gives you a (k+2)-token - Icarus specified the condition that one also already have a (k+1)-token.

someone holding a (k+1)-token without a k-token would not pick up a k-token (or would pass it on immediately)

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 15th, 2005, 3:48pm

on 03/15/05 at 14:17:23, Leonid Broukhis wrote:
 No, a k token and a k+1 token does not make a k+2 token. If a holder of a k+1 token picks a k token, a deadlock is possible.

That is not what I was saying. The k-token can only be picked up if the person already has another k-token. He combines the two to create a single (k+1)-token. If he happens to already have another (k+1)-token (either from previous cycle, or because he got some of the spare starting tokens), he combines the newly-minted (k+1)-token with his other (k+1)-token to obtain a (k+2)-token, and so on. As I said earlier in that post, each level token is worth 2 of the level before.'

Each token level represents a binary digit in the person's token count. Whenever he picks up a k-token, he is really picking up 2k-1 1-tokens, and all the rules for combining tokens are just a codification of adding 2k-1 to his token count. I have expressed it in terms of various levels of tokens because I find it conceptually easier to think of the prisoners leaving items for each other in the room, than to talk about transfering this bit vs that bit of one number to another number.

on 03/15/05 at 14:45:23, Grimbal wrote:
 One optimization that seems to be missing in the solution where token of 1, 2, 4, 8 etc are combined into a single 128-token:  Instead of giving the extra 28 token to one person, spread them to have 1x16, 1x8, 2x4 and 96x1 token.this reduces down to 100 the number of groups to be combined.

I don't quite follow what you are saying here. There are reasons why I identified tokens by level rather than value (mostly for compatibility with other schemes). A 4-token is not 4 tokens, but a single token of level 4. Such a token is worth 24-1 = 8 tokens of level 1.

Since 28 = 16 + 8 + 4 = 24 + 23 + 22, when you give the 28 1-tokens to a prisoner, by the rules he ends up forming these higher tokens immediately anyway. Describing it as giving him 28 1-tokens instead of giving him a 5-token, a 4-token, and a 3-token, is just a convenient short-hand.

I don't see any advantage in giving some of these tokens to other prisoners. By giving them all to one prisoner, if he manages to collect a second 3-token, for example, he can immediately combine it with his initial 3-token, then his 4- & 5-tokens, to create a 6-token. He can do this without having to collect more tokens in the higher level rounds. If the tokens are spread among  other prisoners instead, he has to transfer his 4-token, or receive one, before the tokens can be combined. It is token transfers, not token combinations, that require time, so spreading extra tokens out among multiple prisoners increases time instead of decreasing it.

Not long after AlexH proposed the binary method, others (pa0pa0, biwema) proposed variations that attempted what I think you are suggesting, amongst other changes. But these did not lead to any improvement. Mattian appears to have adopted something similar into his scheme as well, but I haven't figured his out well enough to say for sure if it is the same thing. Rezyk, who got the best time out of binary-based scheme, gave his 28 tokens as a lump endowment, just like AlexH did.

I am currently working on a comprehensive survey of the various schemes suggested in this thread, which I hope to post later in the week. (Which is why I was able to tell you this much about the past history). I hope this will re-invigorate the search, at least to the extent of optimizing past proposals (the best so far, due to gypo, is definitely not optimized).

---------------------------------------------
Time flies when you're pontificating, I guess. I wouldn't of thought that I spent 45 minutes or more on this post, but rmsgrey had not responded when I started it!

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Mar 16th, 2005, 5:12am
OK, I will speak of n-groups for a group of n 1-token.  I think it is confusing to have a 3-token to have 4 items.  :-/

If you give all extra token to one prisonner, there are 99 to have 1 and one to have 29 token.  29 is 1+4+8+16, that is 4 groups.  That makes a total of 103 groups to combine.  If instead you give 16, 8, 4, 4, 1, 1, 1, ..., there are exactly 100 groups.  You replace four 1-groups by one 4-group.

But it is true it reduces the opportunity of multiple groupings, say if the guy with 29 token receives a group of 4.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 16th, 2005, 10:57am

on 03/15/05 at 14:45:26, Grimbal wrote:
 One optimization that seems to be missing in the solution where token of 1, 2, 4, 8 etc are combined into a single 128-token:  Instead of giving the extra 28 token to one person, spread them to have 1x16, 1x8, 2x4 and 96x1 token.this reduces down to 100 the number of groups to be combined.

Grimbal,

I did include this optimization in my solution (around page 14).  The difference in my solution, however, was that instead of arbitrarily assigning these 1, 2, 4 and 8 values to prisoners, my solution was to assign those values at the beginning of each level in order to minimize the the time it would take for trading to begin in that level.  So, for example, the first person in the room in level 4, automatically adds a 4-token to his balance.  If he already has a 4-token, then he simply collects the free one and deposits it again in the room.

Icarus has asked me to provide a clearer description of my solution.  I will do that later today.

Cheers.

Title: Re: 100 prisoners & a light bulb
Post by raven on Mar 16th, 2005, 12:10pm
After following this thread for some many months, and coming to the two current solutions myself, although my version of the second solution (tokens) does vary a little from the one everyone is going with, I have only been able to come up with one possible variant that could possibly make a difference or impact on the overall release time.

I have read all posts in this thread (no really I have) but it's been a while so maybe this idea has already been tested. My apologies if that is the case.

The variant is to include a wildcard cycle before all other cycles. So everyone who enters the room for the first time leaves the light on until the first repeat visitor, who then turns the light off and everyone from then on, during this cycle, leaves the light off.
The prisoner (I call them 'hooligans' in my world) who collected the wildcard-token, would then be required to "even it out" during subsequent regular rounds/cycles in order to integrate their token into the overall scheme of the rules.

What good is this? It could (???) help reduce the days-per-cycle of all subsequent cycles.

Go to http://www.satarah.com/raven/100.html to view the possible impact of this inclusion. *a small javascript that tests for the first revisit to the room -- refresh the page several times to see what the "range" or variance would be (yes, I could have built in 'auto-running' this test 100 or 1000 times and getting the average, but I'm lazy).

Enjoy, Raven

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Mar 16th, 2005, 1:03pm

on 03/16/05 at 10:57:47, mattian wrote:
 Grimbal,I did include this optimization in my solution (around page 14). [...]If he already has a 4-token, then he simply collects the free one and deposits it again in the room.

Hehe...  I went there and discovered that I already proposed my optimization there.  And you already told me the better way to distribute the extra groups.

But of course, it is the other way round.  If he has a similar token he will collect it and merge it with his own.  If he has not, he should leave it for the next prisonner.

To raven:  Yes, I think it was proposed already to start with a "snowball" where everybody passes all tokens to the next one and have the first to re-enter collect all the token from previous prisonners.  But you can not let it roll "as long as there is no re-entry".  You have to set the length from the start, because someone who enters, say on day 20, won't know if the snowball is still rolling.
So you have to reserve S days for the "snowball".  As long as nobody reenters, the light remains on, the first to re-enter (or who enters on day S) collects all the token and swiches off the light.  The remaining days (until day S) the light must remain off.
The question then is how to fix S to make the snowball as efficient as possible.  If S is too low you miss oportunities for a quick start, if S is too high you risk to waste too much time after the first re-entry.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 16th, 2005, 1:20pm

on 03/16/05 at 13:03:34, Grimbal wrote:
 But of course, it is the other way round.  If he has a similar token he will collect it and merge it with his own.  If he has not, he should leave it for the next prisonner.

Absolutely right!  Sorry - my bad.

Title: Re: 100 prisoners & a light bulb
Post by raven on Mar 16th, 2005, 2:15pm
Grimbal,

I assumed that it would be taken for granted, that it would be a fixed-length cycle.

I'm sure optimization would be a simple thing (says the non-math person here), and the expense in days worth the jump start... If the jump start is enough to warrant this addition at all (which is my real question).

Raven

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 16th, 2005, 2:22pm

on 03/16/05 at 13:03:34, Grimbal wrote:
 So you have to reserve S days for the "snowball".  As long as nobody reenters, the light remains on, the first to re-enter (or who enters on day S) collects all the token and swiches off the light.  The remaining days (until day S) the light must remain off.The question then is how to fix S to make the snowball as efficient as possible.  If S is too low you miss oportunities for a quick start, if S is too high you risk to waste too much time after the first re-entry.

According to my simulations, the average time before the first repeat is 12.2 days, and the max out of several million experiments is 50.

It is possible to have several "snowball" phases.  In a subsequent phase, only people who have not seen the light on during the previous phase(s) OR have an odd number of tokens can turn the light on or leave it on. The first person that does not satisfy that condition will collect the tokens accumulated so far and the rest of the phase will be idle.  Intuitively, it seems that the second phase can be beneficial, but I have doubts about the third one.

The problem with the snowball phases is that the number of tokens accumulated will most likely have several bits set and therefore no better than several different people holding the respective power-of-2 tokens.

Title: Re: 100 prisoners & a light bulb
Post by raven on Mar 16th, 2005, 2:45pm

on 03/16/05 at 14:22:20, Leonid Broukhis wrote:
 The problem with the snowball phases is that the number of tokens accumulated will most likely have several bits set and therefore no better than several different people holding the respective power-of-2 tokens.

Back to the drawing board... it is true I'm still looking for a third -- unique system.

:-)

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 16th, 2005, 3:09pm
First of all, I'm sorry, but this is not a new idea. Salem first proposed it for the single leader approach (where it shaves about 3 years off the expected run-time according to the one person who quoted a number.

The same approach was suggested by pa0pa0 for the binary approach, but AlexH says that it would save only a few days at best. Still, Rezyk included it in his version of the binary approach, which remains as the 2nd best run-time so far.

The best run-time, due to gypo, uses a variation (an improved version of a scheme by SWF) of this that picks 10 leaders for a [10, 10] 2-stage solution.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Mar 16th, 2005, 3:28pm
Since Icarus wants to sumarize the available methods, I'd like to write an analysis of this problem.

The first thing to understand is that the problem is not in terms of who switches the light on or off, or how long it remains on.  The light is just a private bit of information that one prisonner sends to the next prisonner.  One prisonner (the sender) decides to leave the light on or off at the end of the day, regardless of its previous state, and the next prisonner (ther receiver) receives that 1 bit of information.  The problem is to make the best use of that little information.  Or to make use of it at all.

The next thing to understand is that the meaning of that 1-bit message must be fixed from the start.  The sender has no way to know who will receive the message, and the receiver doesn't know who sent it.  It could be that the receiver enters the cell for the first time.  Assuming there is a well-defined timeline whereby each message can be identified, (as is the case if there is one stay per day), the meaning of each day's message (leaving the light on) can be decided freely, but it must be decided beforehand, and it must be a function of the day only, regardless of the sender or receiver.  The only thing that can depend on whatever the prisonner experienced, or even on randomness, is the decision to leave the light on.

One possible meaning for message N would be "prisonner (N mod 100) was here", where prisonners are numbered 0..99.  Each prisonner collects and propagates information about all stays he knows about and hopefully someone will reach the point where he knows for sure everybody was there.  It is very slow, but it is an example of propagating information.

Many solutions work in terms of tokens.  Token are distributed among all prisonners and they try to transfer all token to one prisonner.  Obviously it can only happen when each prisonner visited the cell at least once.  A message is these solution has meaning: "I am transfering N token to you".  The sender can leave the light on only if he has enough token to transfer.  If the light is left on, the sender reduces his count and the receiver increases his.  N is a predefined function of d, the day number.  The differences between the strategies are in the choice of the function N(d), and in how a prisonner on a given day decides to transfer or not that quantity of token.

The "single leader" solution can be expressed in terms of transferring token.  The token count is always 1.  Everybody gets one token at the starts.  Everybody leaves the light on if he has any token to transfer. If a prisonner enters the cell for the first time, he has his own token.  If the light is on, he receives one token.  He now has two.  He transfers one by leaving the light on and keeps one.  The first time he enters the cell while the light is off, he can transfer his own token to the next prisonner and return with no token.  From there on, whenever he sees the light on, he accepts the token but immediately transfers it further.  The leader accepts all token by conting one every time he sees the light on and keeps all token by never leaving the light on.  This boils down to the rule where each prisonner switches the light on just once and the leader always turns the light off, counting how many times he does it.

One solution with a "Master counter" and 9 "Assistant counters".  There is a first stage (2600 days) where Master and Assistants collect token until they have 10 (they have received 9).  In a second stage (2600 days) the Assistants transfer token and the Master counts them.  If he receives 9 token in this stage, the wait is over.  In this solution, the first stage simply transfers single token, and the second stage transfers tens of token.  In the first stage, the common prisonners get rid of their one token if they can (i.e. they did not receive one), in the second stage, the Assistants transfer their 10 tokens if they have 10.

There was an optimization to the "single leader" where the first 20 days or so a "snowball" is rolling.  The light remains on as long as the snowball is rolling.  The first prisonner to re-enter the cell in that period collects all the token from previous prisonners and becomes the leader.  For the remaining of the pre-set period, the light remains off.
In that situation, the function N(d) is (1,2,3,4,5,...,20,1,1,1,...).  On the first day, the prisonner surrenders his token to the 2nd.  The second adds his token and passes it on.  This continues as long as the prisonners are new.  As soon as a prisonner re-enters the cell, he has no token to add, so he has not enough tokens to transfer, so he has to keep the tokens and leave the ligt off.  This continues until the end of the "snowball" period, where the count returns to 1 and new prisonners have the possibility to transfer single token.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Mar 16th, 2005, 3:28pm
Then there are the binary groupings.  In this solution, the idea is to move groups of 2^k token that can be combined 2 together to make groups of 2^(k+1), with the aim to get a single group of 128 token.  28 extra token must be added to make a nice round total (in binary, that is).  The transfers are organized in stages:  a first stage is meant to transfer single token, the next stage is to transfer and combine 2-groups, then a stage for 4-groups, etc. up to the stage where 64-groups are transferred, hopefully to end up with a single 128-group.  There was a confusion how to deal with stage changes.  How to avoid a prisonner to send a single token that would be received as a 2-group.  The answer is that the receiver must add to his tokens the count of the previous day, regardless of how well it suits him.  If the prisonner had no token and planned to pass down whatever he receives, he might receive a single token on the first day of the 2-group stage.  In that situation he has one, but has only the possibility to transfer 2.  So he has to get back to his cell with his token.  On the other side, if he had 1 already, he could immediately continue passing on the 2-group.  In general, it is convenient to have long stretches of same group sizes, because then, a receiver of a group who can not combine it can immediately send it further.  If the group size changes all the time, (as in a proposed solution that goes 1,2,1,4,1,2,1,8,...), many prisonners will get stuck with a group that they can not transfer.

I think mattian's proposal of long stages of 1's then 2's, 4's, etc, up to 64's should be best.  I just would add a "showball" at the beginning, i.e. have the N(d) look like: 1,2,3,...,S,1,...,1,2...2,4...4,...,64...64, (and restart 1...1,2...2, etc.).  The question is to optimize the length of the snowball, the lengths of each stage in the initial cycle, and the lengths of the stages in the "repeat" cycles, that are probably shorter

OK, that's it.  I hope it makes sense.  Actually, I just wanted to clarify a few points, like the idea that the light is a 1-bit message, that its meaning must be fixed from the start, and that token received must be accepted, even though they can be passed to the next prisonner, but only if the day's group size allows.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 17th, 2005, 6:42am
Snowballs and badges and crowns, oh my! ;D

This was the thread that originally drew me into the forums, and while I haven't found anything new to contribute, I just thought I'd pop up and say "excellent summary!"  Just for completeness, here are the details of gypo's best run time opening (from page 11, runtime of 3489, wherein a "badge" means a prisoner is collecting 1-tokens and a "crown" means a prisoner is collecting 10-tokens):

on 10/23/03 at 04:29:21, gypo wrote:
 * Initially, all prisoners have one token each, zero badges and zero crowns (same as before). * On day 0 of each cycle, if the light is on, the prisoner gets a badge and three tokens. If the light is off he gets nothing. If he now has one or more tokens or one or more badge, he turns the light on and subtracts one token from his inventory, even if he ends up with a negative number of tokens. If the prisoner has no tokens and no badges, he switches the light off and gets a badge. * On days 1 and 2, the prisoner does nothing if the light is off. If the light is on and he has a token or a badge, he leaves the light on and subtracts one token from his inventory. If the light is on but he has no tokens or badges, he turns the light off and adds d tokens and a badge to his inventory. * On day 3, if the light is off the prisoner does nothing. If the light is on and he doesn't have a badge already, he switches the light off and gets three tokens and a badge. If the light is on and he already has a badge, he leaves the light on and does nothing. * Whoever gets a badge during cycle 0 also gets a crown. * On day 1 of stage 1, if the light is on, the prisoner gets a badge and three tokens, switches the light off and pretends it was off to start with. This opening will result in somewhere between 14 and 25 drones (out of 90) being counted during the first 40 days, which gives you some idea of the power of the method. I haven't really optimised the stage lengths very thoroughly, but this is what I used to achieve the 3489 days: stage 0: 10 cycles of 4 days; stage 1: 2000 days; stage 2: 1500 days; stage 3: 300 days; stage 4: 300 days.

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Mar 17th, 2005, 8:05am
One possible optimisation to gypo's method is to extend the allocation phase by another 2 cycles, to hand out 12 badges, the first four of which are "badge+" and require 9 tokens to fill; the remaining 8 requiring 8 tokens each. It may also be worth tweaking the allocation cycle lengths slightly so earlier cycles drop the third day (pass the badge if you already have one and it hasn't yet been collected, without increasing the snowball) and later cycles add a fourth day (ditto). It may also be worth tweaking the sizes of the mini-snowballs.

The reason for suggesting 12*8ish rather than 10*10 is that someone reported better results with that division when looking at pre-assigned leaders.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 17th, 2005, 7:41pm
Concerning the straight binary solution (no snowball round or other variations) and how to handle the extra 28 tokens:

Suppose at the beginning of a stage, there are L prisoners with the appropriate level of token (call these prisoners "active" for the stage), out of a total of N prisoners. Because of how the binary scheme works, each active prisoner visits the room once, and then becomes inactive - it is impossible for an active prisoner to visit the room and remain active. I will assume that the stage lasts long enough for all active prisoners to visit. The expected time for all active prisoners to visit can be calculated as follows. While k prisoners are active, the probability of one visiting on any particular day is k/N, and the expected time until one does visit is the inverse: N/k. So the expected time from the start of the stage to the visit of the first active prisoner is N/L. The expected time from this visit to the 2nd visit of an active prisoner is N/(L-1). This continues until the expected time between the visit of the 2nd-to-last to the last active prisoner is N/1.

This gives a total expected conclusion time of N * [sum] 1/k  for k=1 to L. (By "conclusion time", I mean the number of days it takes for all prisoners to become inactive in the stage, assuming that the stage lasts long enough. The stage itself may last much longer, as no one knows it has accomplished all it can.)

Now if N is not a power of 2, and no special measures are taken to correct for this, at the beginning of some stages, L is odd. The light starts each stage in the off position (turning it off is part of the previous stage, even if it happens on the same day). Each active prisoner toggles the state of the light, and since L is odd, eventually it will be on when no active prisoners remain, indicating a lone token left in the room, and no one able to pick it up. Call this the (unsuccessful) conclusion of the stage.

Consider a fixed order of prisoner visits, and let us look at the effect of various approaches for fixing this problem. Call the last active prisoner to visit in the uncorrected scheme "Ender".

Grimbal/Mattian's method is to bequeath an extra token to the person visiting on the first day of the stage. If the first visitor was inactive, this makes him active, so he now switches on the light, whereas before he left it off. The next active visitor would have turned it on before, but now he turns it off. And the following active visitor now flips it on, where before he turned it off, and so on. The light bulb is now in the opposite state every day than it would of been in the uncorrected version. The result is that Ender turns the light off instead of on, and no tokens are left over. Note that it is still the same prisoner Ender who concludes the stage in both the corrected and uncorrected versions. So the two versions last the same length of time. Now, however, the stage has a successful conclusion.

---------------------------------------
This post is too long for YaBB, so I am breaking it in two here.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 17th, 2005, 7:42pm
Continuing:

Suppose instead that the extra token is given to some randomly chosen inactive prisoner. The effect of his first visit to the room is to swap the state of the bulb from then on in the stage. If his first visit to the room occurs before that of Ender, then just as before, Ender turns the light off instead of on and concludes the active stage after the same amount of time. If, his first visit falls after Ender's, then Ender will turn on the light, and he will turn it off, extending the conclusion of the stage by a certain number of days (expectation = N*((N-1)/N)T, where T is the number of days until Ender's visit).

Now suppose the extra token is given to a randomly chosen active prisoner. The prisoner is removed from the active list, and the toggle the prisoner induces is removed, flipping the bulb state for all later prisoners. If the chosen prisoner is not Ender, this has no effect on the conclusion time of the stage, as Ender still ends it. On the other hand, if Ender is chosen, then the 2nd last active visitor (call him Pretender) becomes the last active prisoner, which shaves an expected N days off the round. Since Ender has 1/L chance of being the chosen prisoner, the overall expection in this case is a N/L decrease in conclusion time.

Of course, there is no way to pick an active prisoner in advance, so assume that any prisoner is chosen at random. There is an L/N chance the prisoner is active, resulting in an expected -N/L change in conclusion time, and a (1 - L/N) chance the prisoner is inactive, resulting in an expected (N-1)T/NT-1 change in conclusion time, where T = N[sum] 1/k, k=1..L. Total expected conclusion time is T - 1 + (N-L)(1-1/N)T.

For our particular case of N=100, there are 3 such stages: #3, #4, and #5, by my terminology.

For stage 3, L=25, T ~= 100*(3.816) = 381.6 days. And the change in conclusion time for picking a prisoner at random is - 1 + (75)(.99)381.6 ~= 0.6 days.

For stage 4, L=13, T ~= 100*(3.180) = 318 days. And the delta conclusion time is -1 + (87)*(.99)318 ~= 2.56 days.

For stage 5, L=7, T ~= 100*(2.593) = 259.3 days. And the delta conclusion time is -1 + (93)*(.99)259.3 ~= 5.87 days.

So it appears that Mattian & Grimbal's method could (with judicious stage length choices) save an expected 9 days off of simply picking a person at random in each stage to receive the extra token.

However, in AlexH's scheme, they are not given to separate random prisoners, but to the same prisoner. To understand the effect of this, consider these cases:
(1)The chosen prisoner gains a token in stages 1 & 2. (prob 1/4)
Or, the chosen prisoner donates a token in one or the other of these two stages (prob 3/4), but
(2) the prisoner gains a token in stage 3 (prob = (3/4)(1/2) = 3/8).
Or the prisoner does not gain a token in stage 3 (and donates the extra one given him)(prob=(3/4)(1/2) = 3/8), but
(3) does gain a token in stage 4 (prob = (3/8)(1/2) = 3/16).
(4) Or the prisoner also donates his stage 4 token (prob = 3/16).

In case 1, the prisoner is able to build a level 6 token by the end of stage 2, and therefore has no need to take part in stages 3, 4, 5, which now have 24, 12, 6 active members. This changes the expected conclusion times to 377.6, 310.3, and 245 days, saving a total of 26 days over the G/M method.

In case 2, the prisoner takes part in stage 3, but not in stages 4 and 5, which now have 26, 12, 6 active members. Conclusion times are 385.4, 310.3, 245, saving 18.2 days over G/M.

In case 3, the prisoner is in stages 3 and 4, but not in 5. Active members are 26, 14, 6. Times are 385.4, 325.2, 245, saving 3.3 days over G/M.

In case 4, the prisoner is active in all three stages. Active members are 26, 14, 8. Times are 385.4, 325.2, 271.8, costing 23.5 days more than G/M.

The total expected difference is (.25)(-26) + (.375)(-18.2) + (.1875)(-3.3) + (.1875)(23.5) ~= -9.5 days.

So in the end, AlexH's method saves better than 9 days in stage conclusion time over Grimbal and Mattian's. This is not the same thing as saving 9 days in expected imprisonment, but does indicate a better overall performance.

Finally, I end with this question: Does it improve matters to tell the prisoner given the extra tokens to never give away a token in the first two stages? (If he enters the room with the light off, he greedily keeps his token instead of turning the light on.) This attempts to swing matters towards that -26 day total, at the cost of ineffective visits in the first two stages.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 18th, 2005, 8:29am
Hi guys,

Icarus, I know I was supposed to give you an explanation of my results, but I have lost the source code for my original simulation.  I'm in the middle of rewriting it now.  In fact I have developed an engine that will run any strategy defined - ie. The general framework is built and will run an arbitrary strategy that is defined as a set of rules.  I intend to include all the main strategies from this forum and then I will post the finished product and the source code to the forum when it is done, complete with the results of the tests.  As for my own method, at the moment I'm getting about 5000 - so I've left something out (maybe the bit that cheats :-)) in my new implementation, but I will keep you posted.

In brief, the mattian method - I will call it that for now - incorporates an initial analysis phase (which could be used for any of the methods) that aims to optimise the stage durations.  It does this by establishing (using statistics from hundreds of iterations) the lengths L[...] of each stage in a cycle required in order for there to be an X percent chance that everyone has traded by the end of the cycle.  It then determines (again using statistics) the average number of left over traders in each stage after the first cycle and starts all over again by recalculating L based on the remaining traders.  This analysis phase continues until the remaining number traders is less than some threshold T.

The results L of the analysis are then used in the actual simulation.  X% of the time, the prisoners escape within the sum of the first cycle of stages' durations.  X% x (100-X)% of the time, escape time is the sum of the first and second cycles of stages, etc.

The trick then is to chose nice values for X and T.  T is easy - 0.0001 is a good choice.

The analysis phase is a separate method which is analagous to the initial meeting in the courtyard because it runs through test cases to establish some parameters for the strategy.

The testing framework allows you to specify the all the fixed parameters, such as the number of prisoners, for example, and then requires that you implement a single method which defines the behaviour of prisoner when he enters the room given two parameters as inputs : the current day, the state of the light.  Any strategy can be defined by the same set of rules that all prisoners must follow when they enter the room so all the other dynamics of this problem are handled outside the specific strategy handler method.

I will try to run some of the strategies tonight using this initial analysis and see what I get.

As for the mattian method, I believe my best results were around 3500, but only if I chose not to include every 10th iteration on average.  In other words, every now and then, a result of around 15000 would come up and pull the average way up.  That is why I posted a few months ago, asking if we should be considering the overall average to be more significant than the median - so is { 4500, 4501, 4499 } better than { 3501, 3499, 7001 }.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 18th, 2005, 9:14am

on 03/17/05 at 19:42:21, Icarus wrote:
 So in the end, AlexH's method saves better than 9 days in stage conclusion time over Grimbal and Mattian's. This is not the same thing as saving 9 days in expected imprisonment, but does indicate a better overall performance.

Actually, there may be a better way than AlexH's scheme:

One of the other optimizations I have in my scheme is to award the power to be greedy to the any prisoner who has a balance of at least 64 - so he may collect tokens in any stage and never give any away.

A similar strategy could be used for the extra tokens - give 99 prisoners a balance of 1 and the final prisoner a balance of 29 with the power to be greedy until his balance reaches 32.

And then when he (or another prisoner) hits 64, it's back to being greedy.

I will mull over this for a bit - and add it to the sim.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 18th, 2005, 10:12am
Actually!

This is the perfect reason to use a strategy mentioned in some previous posts which use the first three days to handle special cases for optimization.

*Initial balance for each prisoner is 1.

*If a prisoner visits the room on day 1 or day 2, his balance is set to 0.  The prisoner of day 1 switches the light off.

*If the prisoners of day 1 and day 2 are the same person, then on the second day, the light is switched on.

*If the prisoner visiting on day 3 is the same person as on the other two days, he adds 29 to his 0 balance.

*If the prisoner on day 3 is not there for the third time, his new balance is 30 if the light is on, and 31 if it is off.

So after three days, the special prisoner with the excess balance will have a balance of 29, 30 or 31.

*If the prisoner of day 3 has 31, he leaves the light on and his balance changes to 0, otherwise he turns it off and he keeps his balance.

*If the prisoner of day 4 has a balance of 1 and the light is on, then his balance becomes 32, and he switches the light off.  Normal trading begins on day 5.

*If the prisoner of day 4 has a balance of 0 and the light is on, his new balance is 31 and he switches the light off.  Normal trading begins on day 5.

*If the prisoner of day 4 has a balance of 1 and the light is off, Normal trading begins on day 4 with this prisoner.

*  If the prisoner of day 4 has a balance of 0 and the light is off, he leaves it off and trading begins on day 5.

So after four days, the special prisoner (which has not necessarily been the same person throughout the four days), will have a balance of 29, 30, 31 or 32.  And 32 is the most likely outcome by far.

Thus within four days, the most likely outcome is that:

*three prisoners are rendered inactive, and
*one prisoner has hit stage 6. (32-token trading).

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 18th, 2005, 10:41am
Here's another thought,

I don't know if this has been mentioned before - it probably has, and I'm sure you believe that I have read all the posts ... and forgotten a lot.  I think I need to brush up on the details of the thread.  But nevertheless, ...

For this exercise let me refer to days, prisoners and light states according to the following examples:

DAY | PR# | L-S | BAL
-----------------------
D12 : P43 : 0-1 : 01-00
D25 : P21 : 1-1 : 00-00
D98 : P01 : 0-0 : 00-00

* The first means that on day 12 prisoner number 43 swithed the light from off to on and his balance changed from 1 to 0.

* The second means that on day 25 prisoner number 21 left the light on and his balance didn't change.

* The third means that on day 98 prisoner number 1 left the light off and his balance didn't change, etc.

Along the same lines as my previous post which has the likely outcome of a prisoner with a 32 balance after four days, what about this potential optimizing strategy...

Allocate the first N days to chance, as follows.

D01 : P01 : ?-1 : 01-00
D02 : P02 : 1-1 : 01-00
D03 : P03 : 1-1 : 01-00
D04 : P04 : 1-1 : 01-00
D05 : P05 : 1-1 : 01-00
...
...
D38 : P38 : 1-1 : 01-00
D39 : P04 : 1-0 : 01-67 ... <-- LOOK HERE : BAL=38+1+28
D40 : P39 : 0-0 : 01-01
D41 : P40 : 0-0 : 01-01
...
...
DN  : P?? : 0-0 : ??-??

So after N days a prisoner has collected between 1 and N tokens depending on how many prisoners form the sequence without repetition.  A good choice of N might be the average number of days it takes for one prisoner in 100 to be selected a second time.  101 is the obvious maximum, 2 is the obvious minimum.  At the very least, there is a fair chance you could get a prisoner into level 7 (trading 64-tokens) within the first 50 days by combining the sequence count with the excess 28 tokens.

This represents the first cycle.  The second cycle could work the same way except that unlike the first cycle which is terminated by a repeating prisoner, the second and subsequent cycles are terminated by prisoners who do not have the currency to trade in the current cycle - ie. zero balances, inappropriate balances, repeating prisoners within that cycle (but they won't have the appropriate currency anyway).

This idea (as far as I know) is in its infancy, so please feel free to contribute.  It seems as though it may be able to be combined with other strategies, as an optimization.  Although as the unbroken sequences become shorter and shorter with the list of eligible traders, this scheme would ultimately slow the thing down.  But for the first phase, alone, it could establish a healthy leader and may prove very successful.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 18th, 2005, 2:16pm
With reference to the G/M strategy (Grimbal/Mattian) :

Some clarification on the rules for greediness.

Prisoners whose binary representation of their balance, contains more 1's than 0's should be greedy while prisoners with more 0's than 1's should be keen to give up their tokens.

ALSO,

If a prisoner has exactly half the tokens (64), he should be greedy in all levels except in 64-trading.  If he has more than half the tokens, he should be greedy always.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 19th, 2005, 6:41am
Thanks, rmsgrey, for pointing me in an interesting direction!

It had never occurred to me before reading your post that the badges need not require the same number of tokens to fill.  That is, different prisoners with badges (hereafter badgers) can be looking for different numbers of tokens to fill their badges, and, since only filled badges are passed to the crowner, the system still works--the crowner counts filled badges rather than their tokens.

Why is this useful?  Because in the initial short snowball rounds the earlier rounds likely collect more tokens than the later rounds.  By adjusting the size of the badges (and, slightly, the number of days in the individual snowball rounds), we can make it more liekly that all badgers start out needing approximately the same number of tokens to fill their badge, wihch makes the first stage more efficient.  (Since otherwise badgers who need fewer tokens fill their badges early and no longer participate.)

Sticking with 10 badgers for the moment (one of whom is also the crowner), I found the following series of badge sizes (used in gypo's stage 0) result in an average runtime (over 10,000,000 trials) of 3426:

1st cycle 6 days long, one badge of size 12 awarded (and also the crown)
2nd & 3rd cycles 5 days long, two badges of size 11 awarded
4th - 6th cycles 5 days long, three badges of size 10 awarded
7th - 10th cycles 4 days long, four badges of size 9 awarded.

This solution still uses gypo's stage lengths (2000, 1600, 300, 300, ...) which seem to be close to optimum for 10 badges.

Hopefully I can spend some time this weekend investigating solutions with fewer or more than 10 badges--there's still certainly room for improvement: I'm looking to break 3400. ;)

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 19th, 2005, 2:08pm
Just for the record, biwema was the first to suggest that the number of tokens collected by different leaders could differ from leader to leader.

SWF made use of the same idea (with just one person collecting a different amount) to come up with his record setting (at the time) proposal.

Other than those two, however, the schemes have all had constant collection requirements.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Mar 19th, 2005, 2:10pm
Good to know someone's developing some of my suggestions - even if I'm not putting in the hard graft on evaluating potential solutions on this thread, I am generally interested in people's results.

I'm currently wrestling with the concept of a hybridised system, with a mixture of dynamically labelled tokens, and what might well end up as a binary collection method for anonymous or semi-anonymous tokens and aggregates in an attempt to combine the rapid finishing of labelled tokens with the rapid starts of dynamic allocation systems. So far, all I'm getting is a headache, but I've got a feeling there might be something there.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 19th, 2005, 4:36pm
Here is an abbreviated history of ideas in the thread I put together as part of my (still) upcoming survey. They are listed in chronological order, not order of best time. I've chosen these posts because I think they each add a significant idea to what has come before. By "Run-time", I mean the expected length of imprisonment under the scheme. The run-times reported are not necessarily those obtained by the proposer listed, but rather are the best reported by anyone who analyzed any minor variation of the scheme (not including any later mentioned idea). Where I know the run-time to great accuracy, I have denoted it as "Run-time = ". Where I am less sure of the accuracy for any reason, I have denoted it as "Run-time ~ ". The first two run-time values I derived myself from first principles. The others are all values I have found mentioned in posts, and are all obtained from simulations.

The sudden switch back to the much longer running distribution schemes in the last two entries was the result of investigations into a suggestion of mine that distribution schemes might be profitably combined with counting schemes. (So far, this has proved to be a false hope, though apparently rmsgrey still thinks it might work. He had also suggested a somewhat different means of combining the two methods prior to mine.)

I have not included Mattian's or later methods into this history because I am not yet sure what is in them. When I get the time to figure them out, I may edit the history to add them.

History
BanderSnatch (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=0#4) - Complete cycle scheme.  Run-time = 1.0608 x 1044 days.
Captain Caveman (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=0#10) (quoting from a slash-dot site) - Single stage counting scheme ("Leader solution"). Run-time = 10418 days (28.5 years).
sjbrown (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=20#22) - Distribution scheme, stage length = 1, only the prisoner can pass his marker. Run-time ~ 8230 years (per Mattian).
S. Owen (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=20#28) - Distribution Scheme, stage length = 1 (anyone possessing a marker can pass it): Run-time 252 years (per Mattian).
Salem (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=40#43) - Single stage counting scheme with 100 day "snowball" round. Run-time =9367 days (~25.6 years, per Mattian).
AlexH (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#66) - Single stage counting scheme with short "snowball" round. Run-time = 9321 days (per Mattian).
Paul Hammond (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#73) - Multi-stage counting scheme (future cycles start from scratch). Run-time = 3964 days (~10.8 years, per Mattian).
AlexH (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#74) - Multi-stage counting scheme (future cycles are continuations, stage lengths vary between cycles). Run-time ~ 3600 days
AlexH (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#74) - Leaderless binary counting scheme. Run-time ~ 4250 days
biwema (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=100#104) - Counting scheme with mixed-value tokens: Run-time = 3600 days.
SWF (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=120#124) - Counting scheme with multi-leader snowball round (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=120#133). Run-time = 3535.6 days.
Rezyk (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=180#197) - Counting scheme (consolidation round, greedy leader, 2nd cycle degeneration). Run-time = 3532 days.
gypo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=200#202) - Counting scheme (borrowing against badges). Run-time = 3489 days
Paul Hammond (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=240#247) - Distribution scheme with stage length >1. Run-time ~ 54,000 days (148 years)
rmsgrey (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=240#252) - Distribution scheme with varying stage lengths between cycles: Run-time ~ 53,000 days (145 years)

By the way, My kudos for most groundbreaking idea goes to Paul Hammond for introducing the multi-stage concept. This was the seminal post that pushed this puzzle into entirely new territory.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 19th, 2005, 4:39pm
Working on it  - still hovering around 4000 - not sure what I'm missing. Will keep you posted.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 19th, 2005, 5:05pm
By the way, Mattian, when you brought up the matter of how to judge effectiveness of a scheme (whether or not expected release time was the best), you stated that your scheme compared favorably to others in most runs, but had occasional long runs that brought the mean run-time up above that of other schemes.

All staged counting schemes run in cycles (with a semi-exception for Rezyk's, which has only two cycles, the 2nd of which is not like the first). Each cycle consists of a series of stages, and it is only possible for a prisoner to declare victory in the last stage of any cycle. This results in exactly the pattern you described. Assuming the scheme has been optimized for mean run-time, most runs will result in a prisoner declaring in the first cycle. But occasionally things won't work out in this cycle, and a 2nd cycle occurs. This always adds a tremendous amount of time to the run, as victory cannot be declared until the final stage comes around again. On extremely rare occasions, the 2nd cycle will fail, and a 3rd cycle occurs, which once again adds a big contribution to the length of the run. Etc.

In other words, every counting scheme will come in significantly under the mean for most runs (runs with a 1st cycle victory), but occasionally will toss in much longer times (runs with 2nd cycle victory) and on rare occasions toss in an extremely long time (3rd cycle or later victory).

So IF you were comparing your 1st cycle victory runs to their mean run-time, the comparison is invalid, because their 1st cycle victory runs were much shorter too.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 19th, 2005, 5:18pm
Yes, I knew what was causing those nR spikes (where n is the number of cycles and R is the runtime of a succesful one cycle run).

I honestly don't remember if my results included the spikes or not - based on the current numbers, I assumed yesterday that they must have excluded the spikes, but now I'm not so sure - I doubt  I would have submitted them as comparable to the other solutions if I had to doctor them first.  I will have to go back and read my posts.

I'm getting close now though, I can feel it.  If I can save myself another 500 days on average, I get to save face.  :-).

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 19th, 2005, 5:48pm
I wasn't accusing you of doctoring the numbers! You quite plainly stated you were getting the occasional spike:

on 07/03/04 at 22:17:25, mattian wrote:
 My results look something like this:3352294433235929 (this bastard affects my beautiful average so far)317230986345 (and again)29826083 (yet again)These are numbers from a real sample I just ran.  If you ignore all the high numbers, the low numbers are quite nice.

I just wanted to point out that the same situation holds in all multi-stage counting schemes.
____________________________

A more thorough means of reporting these schemes would be to report the 1st cycle victory mean time & probability, 2nd cycle victory mean time & probability, later cycles mean time & probability (one value covering all later cycles), and finally, overall mean time.

This would allow several comparisons between schemes, and possibly point out addition directions for improvement.
____________________________

When it comes to looking for improvements, I would suggest a look at Rezyk's scheme (see the link in my history). With all the other schemes, I have some idea as to why they improved on previous methods. But Resyk's has me baffled. Almost everything I see in it looks either dubious (the consolidation round), or downright going in the wrong direction (degeneration - tokens built in the first cycle are torn apart in the second and collected by a single leader, also binary first 3 stages). Yet somehow Rezyk was able to beat all earlier comers (if just barely), and has been bested by only one proposal since. I am curious what it is that results in Rezyk's fast times. Perhaps exploiting it could improve times farther.

Title: Re: 100 prisoners & a light bulb
Post by SWF on Mar 19th, 2005, 6:48pm
Some of the claims made for various strategies appear to be questionable, so it is a good idea to have somebody verify. I programmed Rezyk's approach and verified the numbers claimed. Back when I was working on this problem, I tried many variations and still have some notes. Long ago I gave up working this problem, but with the renewed interest, thought I would share this information. Unfortunately my notes are not well documented, making it difficult to remember what they mean.

My notes have a table giving how many days needed to reduce 100 prisoners to n prisoners who have each collected similar numbers of signals. Based on those results I made tables for reducing n prisoners down to m for some of the more promising values of n and m.  Finally there is a table for number of days for the m prisoners to pass the information to the final prisoner who knows all 100 have visited. Those tables are bit long to include here, but for the basic method reducing 100 down to 1 in one step took an average of 10391 days, which is slightly different from the 10418 from Captain Caveman. I may have used a slightly different approach that is a little more efficient (perhaps Captain Caveman set the prisoner responsible for collecting signals as the prisoner selected on Day 1, while I may have made him the one who enters on day 2).

One table that is not too long to include here gives mean number of days for using a "snowballing" method plus two stages of counting, with the 'secondary counters' (see my old post for what that means) counting to N, and 'primary counter counting' to M. This first table is for after a fairly crude optimization of length of each stage and only about 20000 cases run to get an average. Due to limited number of cases run, the mean number of days may be accurate to within a few days:
  N   M   Mean Number of Days10   10    353711   12    3544 9   10    353712   16    357414   16    3633 7    9    3654

Using the top three cases from that table, more care was taken to optimize the lengths of the stages and for each case around 10 million cases were run for a more accurate average.  The results were:
  N   M   Mean Number of Days11   12    3535.5510   10    3537.20 9   10    3537.21

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 19th, 2005, 7:31pm
Regarding the validity of schemes in general - I have almost finished the prison model which can run any scheme defined within a single class.

I intend to drop all the schemes into this model so that the numbers can be compared using the same prison engine.  When I have a solid product, I will drop it here for people to use and improve - it will work for anyone who has a JVM installed on their system - I will post it as a single jar file.

In order to define a scheme, one essentially describes the behaviour of a prisoner who is party to that scheme.  The all prisoners inherit from the Prisoner class which implements an interface which mandates the definition of a method called drawConclusion which is passed two parameters - a reference to the lightBulb (a simple class instantiated in the Prison object which provides the Prisoner with the ability to set the bulb state or view the bulb state) and the day since the prisoners were locked up.

The standard Prisoner class which implements the IPrisoner interface defines drawConclusion to unconditionally return false.  Inherited from Prisoner is a class called OptimisticPrisoner which returns true unconditionally and is extended by another class called thinkingPrisoner which is the root of all scheme-following prisoners.  The difference between the two initial prisoners (prisoner and optimisticPrisoner) is that the first remains in prison forever and the second is killed on the first day along with all his inmate friends.  The various schemes in this forum tend to belong to one of three or four groups - binary solutions, multilevel, leader solutions, etc.  I haven't written them yet, but I intend to develop the chain of inheritance such that it mimicks the development of the ideas in each branch of thinking in this forum.

I'm curious to see how the numbers compare to those posted for the various schemes.  INCLUDING MY OWN!!! :-)

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 19th, 2005, 7:39pm
Another point is that we should probably formalise the number of iterations that we consider acceptable.  SWF for example, posted his results recently after 10 000 000 iterations.  Is that enough?  Too much?  Or could we say that a result is considered comparable to the others if it conforms to the requirement that it holds in simulation of 10 000 000 iterations?

Anyone object to 10 000 000 as the standard?

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Mar 20th, 2005, 8:05am
Well, so far, my hybridisation schemes are tending to converge on gypo's scheme anyway, so, while there is something in it, that something looks rather like what we've already got...

A brief summary of (my) current notation (in the hopes of inspiring people):

Token - every prisoner has (at least) one to start. If anyone ever collects them all, the prisoners win.

n-Token - an aggregate of n tokens, usually used in reference to the binary method family of solutions.

Badge - each badge requires a number of tokens to "fill" it. If anyone ever collects all the badges and they're all filled, the prisoners should win.

Crown - the unique designator for the single "leader" both in single-leader and in two stage methods. The prisoner with the crown is responsible for collecting filled badges.

Snowball - a number of consecutive days in which the number of tokens passed increases by 1 each day until someone is unable to donate the token, and gains a large count instead. (the snowball period then has to be comleted before any further transactions)

Label - a unique identifier for a specific object of a specific type. A filled, labelled object can only be copied and not passed, and a given label can only apply to one object - if one prisoner gets two token labels, he has to either pass one label on or obtain an unlabelled token from somewhere. Uniquely, loose labels can be passed by an off bulb.

***********************************************

Some thoughts on optimising for asymmetric badges: at present, the effect of dynamically assigning badges using gypo's method or minor variations is to render some number of prisoners totally neutral (quoted figure is roughly 20+/-5) and leave the badges with required counts distributed over the range 6-10.

It seems to me to be sensible to ignore those initial counts to start with and figure out the optimum setup for counting prisoners starting from a situation with a number of pre-assigned badges and a number of pre-assigned neutral prisoners (or a reduced set of prisoners with a chance of skipping given days and don't look too hard at what happens between stages) set up to match the expected case coming out of the assignment stage, then tweak the assignment stage to match.

So with gypo's figures, you're looking at about 80 active prisoners, which looks like 9 badges, each wanting about 9 tokens, which ends up resembling SWF's solution very closely - allowing for the fact that SWFs badges are symmetric apart from the one paired with the crown.

***********************************************

New thought on hybridisation:

What if you use snowballs and dynamic allocations so that, for instance, badge#1 is created day 1, then filled over the snowball up to day 10, and shared up to (say) day 50, then badge#2 similarly, up to badge#5 or badge#6 then 4 (say) anonymous badges created to take up the slack - a reasonably large number of people will start out with copies of badges #1 and #2, and hopefully later badges up to the end of labelling. The anonymous badges and any unfilled labelled badges are filled during a standard stage 1, the anonymous badges are consolidated to a labelled crown in a standard stage 2, and then the labelled items are shared during a 3rd stage - with substage lengths based on expected numbers sharing each object.

Title: Re: 100 prisoners & a light bulb
Post by Paul Hammond on Mar 20th, 2005, 12:35pm
If people are going to start verifying claimed averages for the various schemes in this thread I ought to concede that the result of 3900 days that I claimed for my scheme must be wrong, judging by the results for obviously superior schemes later on. I remember somebody questioning it at the time, but I never did find the bug in my simulation code which led to the underestimate.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 20th, 2005, 2:36pm
SWF - 10418 days for the single leader solution was not a number Captain Caveman came up with. Note that I said that the values given were not necessarily those of the proposers - instead they were the best values given for any scheme that made use of the ideas listed before, but not after. For instance, all the 3600 day values I gave came from you, SWF, not the proposers, as you stated this value as being exact for a couple of mixed-value-token plans not making use of your multi-leader snowball round, and also said that the [10, 10] binary method did not do much worse.

I also stated (but admittedly, in a way that is easy to miss) that the first two values I gave (1.0715 x 1044 days for the complete cycle scheme, and 10418 days for the single-stage counting method), I myself derived mathematically. They did not come from simulation runs. (To arrive at the complete cycle run-time by straight simulation would take longer than the age of the universe, even on the fastest supercomputers).

It might also be possible to calculate the run-time for the single stage with snowball round solution, but I have not done so yet. It might even be possible for the simple multi-stage solutions, though there are significant difficulties I haven't seen a way around.

Paul Hammond - your erroneous calculation was later, for the binary stages routine. While your 3900 day value for your original scheme is unchecked, it does not seem unreasonable. SWF stated later that the [10, 10] scheme did not do much worse than 3600 days, and that version included AlexH's suggestion that later cycles continue the original stages. If you will recall, in your original scheme if the first cycle failed to produce a release, later cycles were to start over from scratch - everybody acting as if it were day 1 again. Clearly this would result in a longer run-time, but since the first cycle is successful more than 90% of the time, the increase should be by less than 10% - i.e. roughly in the range of 3900 days.

Mattian - 10,000,000 simulations is probably a bit excessive to demand for every number quoted. If all you are doing is giving a general idea of a scheme's run-time, the lesser simulation counts are fine. And some people may not be able to devote the time and processing power to run 10,000,000 simulations. But with any number to be accepted as accurate, at the vary least, the simulation count they come from should be reported.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 20th, 2005, 4:17pm
Okay - the engine is built.  It is not yet well commented and it needs some kind of a user interface - whether it is as mundane as command-line parameters or a fully fledged gui.  Right now, the class containing the main method, is being recompiled every time I change parameters (such as number of prisoners, number of iterations over which to extract an average, which prisoner type to use, etc.)

The first of the results is in:  BanderSnatchPrisoner has been developed and dropped into the prison.  Running the simulation had my computer staring back at me blankly as BanderSnatchPrisoners patiently waited for a sequence of a 100 non-repeating visits.  Rather than wait 3x10^31 millenia for my computer to finish running a single iteration, I modified the problem for the BanderSnatchPrisoner.

The result of 10000 iterations in a prison containing ONLY 10 BanderSnatchPrisoners, is an average escape time of 2775.4017.  This result is close to the probability-based expectation of 2755.7319.

Next victim: Captain Caveman and his Single stage counting scheme.

BanderSnatchPrisoner.java (for those who are interested)
/**      BanderSnatch - Jul 24th, 2002, 2:19am  *  * My first thought on this is rather simple, though in reality it would  * (most likely) take far too long to be practical.  Starting the day of  * the meeting, each prisoner starts counting the days.   As each prisoner  * goes into the room, they leave the light in the off position.  However,  * if they have been in the room once before in the hundred days, they  * turn the light on.  Once the light is turned on, it stays on for the  * remainder of the initial hundred days as a signal to the others that  * someone has been in the room more than once, and hence someone will not  * have been in the room at the end of the hundred days.  On the hundredth  * day, the prisoner turns the light off, starting another hundred day  * cycle.  If, on the last day of any hundred day cycle, the light remains  * in the off position, it can be said with certainty that every prisoner  * has been in the room, since no prisoner has been there twice.  *  * Though this solution would eventually work, probability says that it  * would not work in a timely manner, since it goes in 100 day cycles,  * rather than having the possibility of the hundred days starting at any  * arbitrary time.  */package com.monahansen.prison;public class BanderSnatchPrisoner extends ThinkingPrisoner{      long currentStage = -1;      public BanderSnatchPrisoner(int id, int totalNumberOfPrisoners)      {            super(id, totalNumberOfPrisoners);            this.currentStage = -1;      }      public boolean drawConclusion(IBooleanSwitch lightBulb, long currentDay)      {            boolean conclusion = false;            do            {                  // if the day is 1, 101, 201, etc. we're into the next cycle - reset light                  if ((currentDay % this.totalNumberOfPrisoners) == 1)                  {                        lightBulb.setState(false);                  }                  // if the light bulb is on, just leave the room - no point continuing with this stage                  if (lightBulb.getState() == true)                  {                        conclusion = false;                        break;                  }                  // if it is the 100th day in the cycle, and the light is off, declare freedom                  if ((currentDay % this.totalNumberOfPrisoners) == 0)                  {                        conclusion = true;                        break;                  }                  // if the current stage is equal to my recorded stage, then switch on the light and leave.                  if (((long)(currentDay / this.totalNumberOfPrisoners)) == this.currentStage)                  {                        lightBulb.setState(true);                        break;                  }                  // record visit in this stage                  this.currentStage = (long)(currentDay / this.totalNumberOfPrisoners);            } while (false);            return conclusion;      }}

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 20th, 2005, 6:50pm
That's two for two!

Captain Caveman's scheme checks out in the model.

Based on 10000 iterations, A complete set of 100 CaptainCavemanPrisoners escaped after an average 10415.1657 days - which compares very nicely to the expectation of 10418.

Here is the definition of the CaptainCavemanPrisoner.  By the way, if anyone spots the trend (given that I haven't provided documentation yet) in the definitions of these prisoner models, feel free to write test code and send it to me so that I can plug it into the model.

CaptainCavemanPrisoner.java
/** Captain Caveman - Jul 24th, 2002, 2:46am  * Ok, here's 2 i snagged quickly from /. that I like.  *  * 1:  Designate 1 person to turn the light off.  Everyone else, on your  * first time in the room, IF THE LIGHT IS OFF, turn it on.  (Otherwise,  * leave it on.)  After the designated person turns it off 99 times (or  * 100, if he turns it off for himself...), he can demand their freedom.  *  * This works even if they can't see the bulb from their cells and is  * rather elegant.  */package com.monahansen.prison;public class CaptainCavemanPrisoner extends LeaderElectingPrisoner{      public CaptainCavemanPrisoner(int id, int totalNumberOfPrisoners)      {            super(id, totalNumberOfPrisoners);            if (this.id == 0)            {                  this.leader = true;            }            else            {                  this.leader = false;            }      }      public boolean drawConclusion(IBooleanSwitch lightBulb, long currentDay)      {            boolean conclusion = false;            do            {                  // initialise light bulb to off state on day 1                  if (currentDay == 1)                  {                        lightBulb.setState(false);                  }                  // if the current prisoner is the leader (id=0), and the light is on, collect token and switch off light                  if (this.leader)                  {                        if (lightBulb.getState() == true)                        {                              this.tokenBalance++;                              lightBulb.setState(false);                        }                        // if the leader has all the tokens, then declare it.                        if (this.tokenBalance == this.totalNumberOfPrisoners)                        {                              conclusion = true;                        }                        break;                  }                  // if current prisoner is not the leader, and the light is off, deposit token and switch on the light                  if (this.tokenBalance == 1)                  {                        if (lightBulb.getState() == false)                        {                              this.tokenBalance--;                              lightBulb.setState(true);                        }                        break;                  }            } while (false);            return conclusion;      }}

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 20th, 2005, 8:10pm
Well Icarus, your statement that SJBrown's scheme would take more than 280 years, was accurate.  In fact it would take longer even than 8000 years.

The simulation for 100 SJBrownPrisoners yielded a result of 2986741.59 after 100 iterations.  It will take over 10 hours to run 10000 iterations under this scheme, so 100 (which took 6.5 minutes) will have to do for now.

Update: An overnight simulation of 10000 iterations of 100 SJBrownPrisoners yielded a result of 3005483.0076.

SJBrownPrisoner.java
/** sjbrown - Jul 25th, 2002, 10:09pm  *  * I think I've found another solution.  (the only other two so far were  * the "Leader" solution and the one where it's off on the 101st (or  * 201st or 301st ...) day. )  *  * 100-day Months Pretend every month has 100 days.  Each prisoner is  * assigned a day of the month.  You only switch on the light if you're  * in the room on your day, otherwise you switch the light off.  If the  * light is on when you go in the room, you know prisoner d has been in  * the room.  When you've seen the light on on *every* day of the month,  * you know every prisoner has been in the room.  *  * badabing.DOT  */package com.monahansen.prison;public class SJBrownPrisoner extends RegisterKeepingPrisoner{      public SJBrownPrisoner(int id, int totalNumberOfPrisoners)      {            super(id, totalNumberOfPrisoners);            register[id] = true;      }      public boolean drawConclusion(IBooleanSwitch lightBulb, long currentDay)      {            boolean conclusion = false;            do            {                  // initialise light bulb to off state on day 1                  if (currentDay == 1)                  {                        lightBulb.setState(false);                  }                  // if the light is on, mark yesterday's prisoner off in the register and reset the light to off                  if (lightBulb.getState() == true)                  {                        this.register[(int)((currentDay - 1) % totalNumberOfPrisoners)] = true;                        lightBulb.setState(false);                  }                  // if the register is full, then everyone has visited.                  if (this.registerFull())                  {                        conclusion = true;                        break;                  }                  // if today represents a prisoner that this prisoner can claim has visited, turn on the light                  if (this.isKnownToHaveVisited((int)(currentDay % totalNumberOfPrisoners)))                  {                        lightBulb.setState(true);                        break;                  }            } while (false);            return conclusion;      }      public boolean isKnownToHaveVisited(int prisonerId)      {            boolean result = false;            if (this.id == prisonerId)            {                  result = true;            }            return result;      }}

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 20th, 2005, 8:37pm
Okay, S. Owen's scheme also looks pretty accurate.  The SOwenPrisoner simply extends the SJBrownPrisoner and checks his register to find a match rather than just looking at himself.

A sample run of 1000 iterations using 100 SOwenPrisoners yielded an average escape time of 91957.838 days (~250 years) and execution time was about 2 minutes.

Update: A 20 minute simulation of 10000 iterations of 100 SOwenPrisoners yielded a result of 91980.523 days.

SOwenPrisoner.java
/** S. Owen - Jul 26th, 2002, 10:11am  *  * I believe I have the answer. It does not assume things that probably  * aren't implied by the problem, like that the prisoners can see the  * light bulb from their cell, or that they can gather after the first  * day.  *  * The idea is that the prisoners will use the state of the light switch  * to (gradually) communicate information about who has been in the  * cell, from one day's prisoner to the next, until someone knows for  * sure that they've all been in there.  *  * The night before, they gather and assign themselves numbers from 0 to  * 99. They then agree on the following rules for what to do in the room:  *  * 1) Let D be the current day. If you know that prisoner # D(mod 100)  * has been in the room, leave the light on. If you do not know that,  * leave it off.  * 2) If the light was on when you came in, then you know that prisoner  * (D-1)(mod 100) has been in the room before - remember that.  *  * For example, if I am prisoner #59, and go in on day 845, and I see  * the light on, I know that #44 has been in there. Furthermore, if I  * know that #45 has been in somehow, then I leave the light on to  * spread that info to the next day's prisoner.  *  * This process only gets started when some prisoner X goes in on a day  * that is equal to X, modulo 100 (i.e., #33 goes in on day 433, and  * since he obviously knows that #33 has been in the room since he's  * there now,  he leaves the light on. If tomorrow, #78 walks in, now  * #78 knows that too).  *  * Eventually the info will spread enough so that someone knows for sure  * everyone has been in the room.  *  * I ran a little simulation, and with 100 prisoners, it takes them  * about 95,000 days on average to know they've all been in there  * (though on average they will all have visited after about 450 days).  */package com.monahansen.prison;public class SOwenPrisoner extends SJBrownPrisoner{      public SOwenPrisoner(int id, int totalNumberOfPrisoners)      {            super(id, totalNumberOfPrisoners);      }      public boolean isKnownToHaveVisited(int prisonerId)      {            boolean result = false;            if (register[prisonerId])            {                  result = true;            }            return result;      }}

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 21st, 2005, 5:19pm
SalemPrisoner did not disappoint, coming in at 25.6 years (as expected).  10000 runs of 100 SalemPrisoners yielded a result of 9367.4935 days.

SalemPrisoner.java
/** Salem - Jul 28th, 2002, 9:49am  *  * Here is a modified solution which could cut down on the expected time  * it would take for the prisoners to get out.  *  * It is based on the "leader" idea, but you get a good jump start Smiley  *  * The first person to go in the room 2 times is the "leader".  * He turns on the light. If he goes in for the second time on day 65,  * then he knows 64 prisoners have been in the room.  * Nobody does anything else until the 100th day.  *  * Note: this first set of 100 days creates four groups of prisoners:  * Group A) inmates that entered the room for the first time and the  * light was off.  * Group B) inmates that entered the room for the first time and and the  * light was on  * Group C) inmates that did not enter the room  * Group D) the leader who entered the room twice and turned on the  * light.  * The person that gets picked on the 100th day has a special job. If  * they are from group A or group D, they turn off the light. If they  * are from group B or C, they leave the light on.  *  * After the first 100 days, the solution is just like the "leader"  * solution. Here is what each group does the next time they are  * selected:  *  * Group A) nothing, they have already been counted  * Group B) turn on the light the next time they enter the room and the  * light is off  * Group C) turn on the light the next time they enter the room and the  * light is off  * Group D) turn off the light if the light is on, decrement the number  * of people left to enter the room.  */package com.monahansen.riddles.hundredprisoners.prisoners;import com.monahansen.riddles.hundredprisoners.prison.IBooleanSwitch;public class SalemPrisoner extends CaptainCavemanPrisoner{      public SalemPrisoner(int id, int totalNumberOfPrisoners)      {            super(id, totalNumberOfPrisoners);      }      public void assessLeadership()      {            this.leader = false;      }      public boolean drawConclusion(IBooleanSwitch lightBulb, long currentDay)      {            boolean conclusion = false;            do            {                  // initialise light bulb to off state on day 1                  if ((currentDay == 1) || (currentDay == (this.totalNumberOfPrisoners + 1)))                  {                        lightBulb.setState(false);                  }                  // if the day is less than snowball duration, do snowball                  if (currentDay <= this.totalNumberOfPrisoners)                  {                        // if the light is on during this period, just leave                        if (lightBulb.getState() == true)                        {                              break;                        }                        // if you have not been before, remember that you've been here now, and leave                        if (this.tokenBalance == 1)                        {                              this.tokenBalance = 0;                              break;                        }                        // if you're here for the second time, become the leader and collect tokens for the number of days past                        if (this.tokenBalance == 0)                        {                              this.leader = true;                              this.tokenBalance = (int)((currentDay - 1) % this.totalNumberOfPrisoners);                              //turn the light on to signal other prisoners that they're still active.                              lightBulb.setState(true);                              break;                        }                  }                  conclusion = super.drawConclusion(lightBulb, currentDay);            } while (false);            return conclusion;      }}`

Title: Re: 100 prisoners & a light bulb
Post by SWF on Mar 21st, 2005, 7:30pm
Some clarification to my recent post.  Based on rmsgrey's terminology, the beginning of the method I used to get 3536 days was not really "snowballing", maybe "dynamic allocation" is a better term. Also, in those runs not all of the prisoners doing the counting, count to the same number unless the number of counters evenly divides into 100.  The workload was distributed as evenly as possible: some count to n others to n-1.

The variation in number of days can be quite large. The single leader method has a standard deviation of around 1045 days, so over a million simulation runs would be required for an accuracy within a day. After thinking some more about it, when my simulations came up with 10391, that was probably inaccuracy from using just a couple thousand runs rather than a different method. That value was made while generating a large table of different conditions for use in identifying the most fruitful approach, so it was not an extensive run. I do see that the analytical solution for a single predefined leader with a total of N prisoners requires approximately,
N*(N-1+gamma+ln(N-1)) days
giving 10417 with n=100 (gamma = Euler's constant = 0.577...), or exact value can be found by adding up a series.

The method with a time of 3536 days had a standard deviation of 607 days.

A particular instance I was thinking of that should be further checked is the claim of around 3500 days for with 7 stage binary (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=105#105). I commented on it here (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=120#123).

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 21st, 2005, 8:09pm

on 03/20/05 at 16:17:54, mattian wrote:
 Rather than wait 3x10^31 millenia for my computer to finish running a single iteration, I modified the problem for the BanderSnatchPrisoner.

Some people are so impatient! Thanks for giving some reasonably hard numbers to these early efforts. I'll have to update that history, but will wait to see what else you come up with before bothering to do so.

I hope to have my promised summary ready to post tomorrow. but it may take until Thursday - and even that is assuming nothing else comes up to distract me. (like last week) The big hold-up is that I am trying to translate all the schemes into a common idiom, and sometimes it can be difficult to do.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 21st, 2005, 9:31pm
Icarus, I think your summary might help me out a bit.  Java's not very good at true multiple inheritence and these problems seem to be borrowing from each other in a less than tree-like fashion.  Perhaps with some established terms and conventions, I can rework the class hierarchy so that it behaves itself.

I will continue to post results as I implement the prisoner types - but I too have to find the time - it has only taken about 20 minutes to implement each prisoner... not including the time spent to rework the whole prisoner heirarchy each time (since I didn't sit down before hand and map that part out as perhaps I should have done).

Anyway I will try to get some further results up tomorrow.  And when I've finished these, I will drop the jar file here on the forum for public scrutiny.  If I can find the attachment button - I know I've used it for images before, but now I can't find it.  Oh well.

Later.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2005, 7:36pm
Okay, here is my promised summary. The numbers are sometimes out-of-date since mattian is reviewing them. I will try to update them sometime soon, but for now I want to get this posted.

As much as possible, I am going to translate the various schemes into a common idiom of what I call virtual items. So I will start off with general definitions and descriptions. Except for specifics of terminology, this will be familiar to anyone who has studied the various schemes. I have tried to stick to established terminologies when I can.:

A virtual item is a conceptual object prisoners may consider themselves as possessing, and which they pass by means of the light. Virtual items represent messages that the prisoners exchange. Three kinds of virtual items come into play in these schemes:

• markers are virtual items that can be copied. A prisoner who passes a marker also retains it in his own inventory.
• tokens are virtual items that cannot be copied. A prisoner who passes a token removes the token from his inventory.

Because tokens and markers represent messages, a separate type of token or marker is needed for each message that needs to be passed. In all the schemes thus far suggested, the various messages that need to be passed are each assigned a number k, and the corresponding items are called "items of type k". I will also use "level" for "type" when talking about tokens and badges. Badges also have a type, but in their case, the type indicates what task the prisoner is required to perform. I will also refer to an item of type k as an "item #k".

For example, in the Distribution Scheme, at the initial meeting each prisoner is assigned a number k and is "given" a marker of type k. The marker represents the message "Prisoner #k has visited the room" (which will be true by the time he can actually pass it).

When passing items, the receiving prisoner needs to know what kinds and types of items he is receiving. This is accomplished by breaking the passage of days into (almost) discreet blocks called stages. During each stage, rules tell the prisoners what kinds, types, and amounts of items they can pass and receive, and how the passage is accomplished. Stages come in two general kinds:

• Typical stages are assigned a type, just like items. During these stages, only markers or tokens of the same type can passed, and only one can be passed at a time. Badges are not passed. When a prisoner who is eligible to pass an item is in the room and the light is off, he signals the pass by turning on the light. When a prisoner who is eligible to receive the item enters the room and finds the light on, he adds the item to his inventory. If the item is a token, he also turns the light off.
• Atypical stages follow their own special rules, which differ from scheme to scheme. I will also call atypical stages rounds. (Not for any good reason, just because I've noticed a tendency to do so in my earlier posts, and am not going to bother fighting it! :P) Badges can only be passed out at the initial meetings, or during atypical stages.

Stage End: The last prisoner to visit in each stage has to turn off the light if he finds it on, to prevent the first visitor in the next stage from receiving an erroneous signal. This means he must also pick up whatever items are available. Stage rules must always allow for this final-pick up. If the prisoner is unable to use the items directly, he must wait for another stage in which he can pass them on. Since the stage is ending, the prisoner is not able to pass any item, and thus the prisoner beginning the next stage is unable to receive any item. This inefficiency is overcome by letting the stages overlap by 1 day. During this overlap, the first half of the visit belongs to the ending stage, so the prisoner receives any items according to the ending stage's rules, but the second half belongs to the beginning stage, so the prisoner passes items according to its rules. The effect of this is to shorten the length of each stage by 1 day.

The stage length is the number of days the stage lasts. stage order determines when each stage starts and ends. Both are set during the initial meeting, as this is the only time all the prisoners can have the same knowledge. Each stage attempts to accomplish some task. Because of the probabilistic nature of the problem, there is no guarantee that any task will be accomplished in a finite amount of time. If there is only one task to be accomplished in the scheme, then only one stage is needed, and it can be infinite in length. Otherwise, stage lengths must be finite. In order to give the task enough time to be accomplished, and infinite number of stages must be assigned to the same task. If the first fails to accomplish what is needed, the process is continued when the next stage assigned to it comes around. Most commonly, a typical stage for each type of item will occur in a repeating sequence. Each such repetition of the sequence is called a cycle. Atypical stages may be distributed in and around the cycles, though most commonly they occur only at the beginning of the first cycle.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2005, 7:38pm
All but one scheme fits the virtual item model. The sole exception is the Complete Cycle scheme (I could make it fit too, but the result is unnatural, and harder to understand than the straight explanation):

Complete Cycle Scheme: BanderSnatch
The days are broken into 100-day cycles. The first prisoner of each cycle turns the light off. No one turns the light on except on their second visit to the room in the cycle. If the prisoner on the last day of the cycle finds the light off, and has not visited before in this cycle himself, he declares that everyone has visited. Just as with stages in the virtual item methods, each cycle may overlap one day with its neighbors, giving an effective cycle-length of 99 days.

This scheme is easy to analyze mathematically. For N prisoners, there are N! ways they can be selected in a cycle without repeats, out of NN total combinations, so the probability of a successful cycle is N!/NN. The success or failure of each cycle is independent of all other cycles, so the expected number of cycles until release is NN/N!. The run-time (expected number of days until release) is (N-1)NN/N!. For N = 100, this is 1.0608 x 1044 days. (In my original number that I quoted in the history, I forgot about overlapping the cycles.)

---------------------------------------------------------------------------------------------

Distribution Schemes:

In distribution schemes, the prisoners are assigned numbers from 1 to N (for N prisoners), and for all k, prisoner k is given a marker of type k at the initial meeting. Cycles consist of stages of types 1 through N in order. There are no atypical stages.

Stage rules: During stage k, any prisoner having a marker of type k (initially, only prisoner k) may turn on the light. Everyone who visits during the stage and finds the light on adds marker #k to their inventory if they do not already have it. The last visitor of the stage turns off the light.

Victory is declared when one prisoner has all N markers in his inventory.

The only difference between the various Distribution schemes is stage length. Since the situation is symmetric with respect to the prisoners, within a cycle, all stages have the same length. But stage lengths in different cycles may differ. The schemes will be indicated by a sequence <s1, s2, ...>, where s1 is the common stage length for the first cycle, s2 is the stage length for the second cycle, etc. "..." means that the last stage length is repeated for all future cycles.

<1, ...> sjbrown, S. Owen: Run-time = 91980 days (~ 252 years), based on 10,000 runs.
<s, ...> Paul Hammond, rmsgrey: Run-time ~ 54,000 days for 40 <= s <= 150.
<s1, s2, ...> rmsgrey: Run-time ~ 53,000 days for 200 <= s1 <= 400 and 30 <= s2 <= 70.
<5, ...> mattian: Run-time ~ 50,000 days
(I am leary of this, since it seems at odds with rmsgrey's earlier values. Perhaps someone can double check all these values to see if they are correct.)

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2005, 7:40pm
Counting Schemes:

Unlike Distribution schemes, there are numerous variations to counting schemes. Instead of markers, counting schemes make use of tokens, and of badges to tell who collects the tokens. In counting schemes, every prisoner is given a token of level 1 (also called a simple token). Some prisoners may also be given extra simple tokens either at the initial meeting, or at later times in the scheme. The total number of simple tokens given out is called the target T, which may be greater than the number N of prisoners. The object of counting schemes is to collect all T simple tokens (or their equivalent) into the hands of a single prisoner. To facilitate movement of tokens, simple tokens are gathered together into groups, which are represented by the creation of higher level tokens. Each higher level token is assigned a fixed number of tokens of the next lower level. When a prisoner has collected this amount of the lower level token, he uses them to create the higher level token. For instance, in Paul Hammond's original scheme, there are 3 levels of tokens. Each token of level 2 is made from 10 simple tokens. Each level 3 token is made from 10 level 2 tokens. Every token has a value equal to the number of simple tokens it is made from. Level 1 tokens always have a value of 1. In Paul's scheme level 2 tokens have a value of 10, and level 3 tokens have a value of 100. Since only 100 tokens exist, only one level 3 token can be made, and it's creator declares victory upon doing so. For this reason, Paul's is a bi-level scheme: once the third level is reached, the scheme ends. A similar pattern is followed by all counting schemes. The highest level token of the scheme has as value the target T, and its creation signals victory, so it does not actually exist within the scheme. For any scheme, the worth of tokens will be expressed by a sequence in square brackets: [n1, n2, ..., nm]. ni is the number of level i tokens required to create a level i+1 token, and is called the level i multiplier. The scheme is called a m-level scheme, and the target is n1 * n2 * ... * nm. So Paul's scheme is represented by [10, 10], and has 100 as its target.

Typical stage rules: Counting schemes may have both typical and atypical stages. In a stage of type k, only level k tokens may be passed. Prisoners who can pass or receive a token are called active. Those who cannot are inactive. With two exceptions, the only people who can pick up a token in a typical stage are those with an unfilled badge of the same level, or the last visitor of the stage. Everyone who has a token of the right level and does not have an unfilled badge is able (and required) to pass a token if the light is off when they visit.

Badges: For stages of level k with leaders, badges of level k are distributed either at the initial meeting, or by special rules during the scheme. The number of level k badges is T divided by the value of a level k+1 token. For each badge, the prisoner holding it is required to collect nk tokens of level k. Immediately upon accomplishing this, he replaces the nk level k tokens with a single level k+1 token. The badge is then said to be "filled". If a prisoner has more than one level k badge, he must fill them separately.
The top level of a scheme can have only 1 badge. This badge is often called the crown. As a general rule, if someone gets a level k badge, it also acts a badge for all lower levels (this requires fewer token passes than giving the lower level badges to some one else). In particular, whoever gets the crown is a leader in all stages, and is sometimes called the "primary leader".

The two exceptions thus far proposed to the badges rule occur when the level multipler for the stage is 2, or else when it is 3 and the stage is the highest level (so there are only 3 tokens of that level to be collected). A stage with level multiplier 2 is called a binary stage. For a binary stage, anyone with a token of the right level is required to pass it at first opportunity, and only those with the same level token can pick it up. When they do, they combine their two tokens to create a token of the next level. In either case – passing or receiving, the prisoner no longer has a token of the right level, and becomes inactive. The top-level stage with multiplier 3 is called a final trinary stage. Only the prisoners possessing the 3 tokens for the level are active, and pass if and only if they have only one token in their possession. Once someone gathers 2 of the tokens, he receives only, until he picks up the third and declares victory.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2005, 7:41pm
Typical stages occur in order of increasing levels within cycles. The length of each stage varies from level to level, and from cycle to cycle. The progression of stage lengths will be denoted by a sequence broken up into cycles: <(s11, s12, ..., s1k), (s21, ..., s2k'), ... >. Stage lengths for atypical stages will be denoted by a *. Typical stages in each cycle occur in increasing order of level. A "..." after the last cycle indicate that it is to be repeated indefinitely. For example, <20*, 24*, (2000, 1000, 500, 500), (300, 300, 300, 400), ...> indicates a 4-level scheme starting off with two atypical stages, one of length 20, followed by one of length 24. level 1 stage length is 2000 for the first cycle and 300 for all future cycles. Stages 2, 3, 4 go from 1000, 500, and 500 days respectively in the first cycle to 300, 300, and 400 for all future cycles.

A common atypical stage, called a snowball round can be applied to several schemes. The snowball round occurs at the beginning of the scheme and (for schemes with leaders) passes out a single badge. The prisoner on day 1 leaves his simple token by turning on the light. Later visitors leave their token by leaving the light on. The first prisoner to visit who is unable to leave a token (either because he has been in the room before and no longer has a token to leave, or because he is the last visitor of the stage, or because special rules of the scheme prevent him from doing so) turns off the light and picks up all the tokens left in the room. This number is determined by the day number. If he visits on day k, then he picks up k-1 tokens. In addition, he is also given a badge (usually, the crown). No one is allowed to turn on the light during the snowball round except the prisoner on day 1, so once the light is turned off, the rest of the round is inactive. The effect of the snowball round is transfer a large number of tokens to a single prisoner in just a few days. Unfortunately, it is only worthwhile when a large majority of the prisoners have tokens to leave, which is why it is only done at the start of the scheme.

Multi-badge versions of the snowball round figure significantly in the fastest schemes, and will be described when those schemes are discussed.

[100] <[infty]> Captain Caveman

Captain Caveman quotes this solution from a slash-dot site. The crown is given to a randomly chosen prisoner at the initial meeting. Only he can collect tokens. Everyone passes their token at the first oportunity (the first time they enter the room with the light off).
Its run-time is calculable mathematically: Assume a total of N prisoners. If k prisoners (including the leader) are still active at day D, each has a 1/k probability of being the first active prisoner to enter after this date. Assuming the light is off on day D, the leader's next visit is successful if and only if he is not the first active prisoner to visit after D. So, when k prisoners are active, he has a (k-1)/k probability of having a successful visit. Which means the expected number of visits before success is k/(k-1). Each successful pass reduces the number of active prisoner by 1. So expected number of visits the leader must make is the sum of the expected number of visits with k active prisoners from k=N down to k=2 (once k=1, victory is declared). Decreasing the index k by 1 gives:
expected # of visits = [sum]k=1N-1 (k+1)/k = N –1 + [sum] k=1N-1 1/k

Since there are N prisoners, visits come at an expected interval of N days, giving a run-time of N(N-1) + N[sum]k=1N-1 N/k.
For N=100, this gives 10417.74 days, or 28.52 years.

[100] <100*, [infty]> Salem

This scheme adds a 100 day snowball round. Run-time = 9367 days (25.6 years), based on 10,000 runs.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2005, 7:43pm
[100] <29*, [infty]> AlexH

AlexH suggested cutting the snowball round to only 29 days. This results in a run-time of 9321 days, about 46 days shorter than Salem's, based on 10,000 runs.

[10, 10] <(2600, 2700), ...> Paul Hammond

Paul introduced the concept of Multi-stage schemes with this version. As a special rule, if a cycle fails, the next cycle starts over from scratch (everyone gets their original tokens & badges back). 9 badges (level 1) and 1 crown are passed out at the initial meeting.

Mattian (who has supplied most of the numbers above) gives a run-time of 3964 days (~10.8 years) based on 10,000 trials.
AlexH suggests that starting over is not necessary when a cycle fails, and decreasing stage lengths in later cycles. All later schemes incorporate these suggestions.

[10, 10] <(?, ?), (?, ?)...> SWF

SWF reports that he was able to get run-times slightly over 3600 days (9.9 years) with this variation, but does not report what stage lengths he used.

[ 2, 2, 2, 2, 2, 2, 2] <(774, 705, 639, 577, 520, 448, 375), (298, ..., 298), ...> AlexH

In AlexH's Binary Stages scheme, all stages are leaderless, and the target is 128. The extra 28 simple tokens are given to a single prisoner at the initial meeting (who immediately converts them into a token each of levels 3, 4, and 5). (Grimbal and mattian suggest instead having the level 3, level 4, and level 5 token appear in the room on the first day of their respective stages. By my calculations this should add about 9 days to the optimal run-time for a binary scheme over AlexH's method. I suggest having the extra tokens appear on day 2 of the first stage, and a rule be added that no can pass a token if he also possesses a higher level token – he can only receive. I have no estimates on my method at this time).

AlexH reports a run-time of ~ 4500 days
(SWF reports a run-time of 4250 days, but does not give stage lengths, or any other information.)

[ 2, 2, 2, 2, 2, 2, *]  (interweaving stages of length 1) pa0pa0

This is an odd scheme notable for introducing the "token" concept. The target is 100. All stages are leaderless until the single level 7 token (value=64) is constructed. It's constructor is then given the crown and searches for the remaining tokens – he only receives tokens from then on. Once he has collected the remaining tokens (of levels 3 and 6), he declares victory.

Stages in pa0pa0's method are all 1 day in length and are interweaved: If m is the highest exponent such that 2m divides the (day-count modulo 64), then the stage level is m.

While pa0pa0's method has some interesting ideas, it's most important contribution is in the lessons learned department: short stages are a bad idea, making it very hard to pass the higher level counters around. Jonathan_the_Red estimates a run-time of about 2500 years.

[ 2, 2, 2, 2, 2, 4]  <(550, 500, 424, 375, 350, 300), (150, ..., 150), ...> biwema

The crown for stage 6 is assigned in the initial meeting, and the extra 28 tokens are given to the leader. The other 5 stages are leaderless.
No run-time was ever given.

[3, 3, 2, 2, 3]  <(no stage lengths given)> biwema

Target =108. badges for stages 1 and 2 are assigned at the initial meeting. The extra tokens are given to 8 of the stage 1 leaders. The remaining stages are leaderless. No run-time was given.

[5, 5, 4]; [5, 4, 5]; [4, 5, 5]  (no stage lengths given) AlexH, biwema

AlexH hints that the [5, 5, 4] scheme should save about 330 days over the [10, 10] scheme. This would make it the record setter if true, but I don't think it is likely. biwema suggests that all three should perform about the same, but [5, 5, 4] should be slightly faster.

No run-times were given for any of these.

[12, 9] <(2252, 1610), (302, 358), ...>; [10, 11] (no stage lengths given) SWF

SWF reports a run-time of 3600 days for both these methods (stage lengths for the second are probably similar to, if not the same as, those for the first). In both cases, the extra tokens are given out at the initial meeting, 1 each to the secondary leaders (the leaders who did not receive the crown).

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2005, 7:44pm
[12, 9] <3*, 2* x 8, (2252, 1610), (302, 358), ...> ; [10, 11] <3*, 2* x 10, (???),...> SWF

(The "2* x 8" notation is a shorthand for saying that the 2* stage occurs 8 times.) These schemes are identical to the previous, except the badges and extra tokens are handed out during the atypical stages (one spare token for each badge other than the crown). The crown is handed out in the initial round of length 3. The level 1 badges and spare tokens are handed out 1 each per the length 2 rounds. The special rounds do not overlap with the surrounding stages.

During the crown round, the first visitor leaves his token, but does not touch the light. The 2nd visitor turns on the light if he is able leave another token. The third visitor receives the crown, and one token if the light is off, or two if the light is on. The visitor leaves the light off.

During the badge rounds, the first visitor passes a token in the normal fashion if he can. The second visitor picks up a badge, a spare token, and any token left from the previous visitor.

SWF reports equal performance again between the two schemes. Run-time = 3535.6 days (9.7 years), based on 11 million trials. Std Dev = 607 days, median = 3370 days.

rilgin offers a variation of SWF's badge allocation rounds that was never applied to any scheme, but may improve on SWF's. However before anyone attempted this, gypo proposed an even better idea.

[2, 2, 2, 16] <20*, 8*, 8*, 4*, 4*, 4*, 380+330, 330+300, 300+200, 1650, 500*, 300*, [infty]*> Rezyk

As one might guess for the stats above, Rezyk's scheme is convoluted. The first 20 days are given over to a straight snowball round, in which the crown is given. Since the target is 128, the 28 spare tokens  are also given to the leader (the recipient of the crown).

Following the initial snowball rounds, 5 more snowball rounds are held: the first two for 8 days each, and the rest for 4 days each. In these rounds, the leader is not allowed to pass a token (he can always receive them).

Next comes the typical stages for levels 1, 2, 3, and 4. The 3 binary stages are leaderless, but have special rules for the leader: Each is broken into 2 parts (lengths indicated by the + signs above). During the first part of each stage, the leader is not allowed to pass a token. During the 2nd part of the stages, he may pass a token only if he does not have any lower level tokens.

The level 4 stage is a straight-forward typical stage with only one leader.

Unlike every other multi-level scheme proposed,  Rezyk's does not have cycles. Instead, if the level 4 stage fails to result in victory, Rezyk proposes a process I call Devolution. Starting with the level 4 stage, and in all later stages, only the leader can ever receive a token.
At the start of the next stage, all prisoners with level 4 tokens break them back into two level 3 tokens. For the next 500 days, the leader tries to collect any that he does not already possess. If he fails to collect all of them, then another stage starts, and everyone with level 3 tokens splits them back into two level 2 tokens, and the leader tries to collect these for the next 300 days. Finally, if he still isn't successful, everyone possessing a level 2 token splits it into two level 1 tokens. The leader then attempts to collect all of them, with the stage lasting until he succeeds.

At first glance, Rezyk's scheme seems an unlikely candidate for speed, yet it beat all previous schemes, and to date has only been beaten by one other. This scheme is also notable in that Rezyk introduces the badges and crown terminology with it. He reports a run-time of 3532.0 days (9.7 years) based on 1 million trials. Std Dev = 752 days.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2005, 7:45pm
[10, 10] <4*x10, (2000, 1500), (300, 300), ...> gypo

gypo takes the standard [10, 10] scheme and adds 10 badge allocation rounds of 4 days each to the start. The key behind his method is that he allows leaders to borrow tokens to avoid picking up a second badge. The badge allocation rounds have the following rules:

Day 1) If the visitor has a token, he leaves it in the room (turning the light on). If he does not have a token, but does have a badge, then he borrows a token (leaving him with a negative token count) to leave in the room. If he has neither token nor badge, he receives a badge and leaves the light off.
Days 2 & 3) If the light is off, the prisoner does nothing. If the light is on, and the prisoner has a token or a badge, he leaves a token in the room (borrowing if needed) by leaving the light on. If he has neither token or badge, he turns off the light and picks up a badge and 1 fewer tokens than the stage-day count (1 token on day 2, 2 tokens on day 3).
Day 4) If the light is off, or if the light is on and the prisoner has a badge, he does nothing. If the light is on and prisoner does not have a badge, he turns the light off and picks up a badge and 3 tokens.
Day 5) (This day overlaps with the next stage, so it does not count towards stage length). If the light is on, the prisoner turns it off and picks up a badge and 3 tokens (even if he already has a badge). Otherwise, he does nothing.

The first badge allocated is the crown.

gypo says that the badge allocation rounds collect between 14 and 25 tokens from non-leaders before the typical stages even start. Run-time is 3489 days (9.55 years), based on 1 million trials. Std Dev = 664 days.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 22nd, 2005, 8:27pm

on 03/22/05 at 19:45:06, Icarus wrote:
 Day 1) If the visitor has a token, he leaves it in the room (turning the light on). If he does not have a token, but does have a badge, then he borrows a token (leaving him with a negative token count) to leave in the room.

Must read "potentially leaving him with a negative token count".

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 22nd, 2005, 8:29pm
Icarus, if this is the summary, I'd hate to see the full document.

Oh wait - I suppose it lives in the 20 pages of this thread.

Wasn't at home tonight - so I haven't implemented any more prisoners yet.  Tomorrow I should have quite a bit of time - assuming I don't spend the whole night reading Icarus' summary - so I should be posting some more results then.

I also have to rework the class/interface hierarchy with some more foresight, but I won't let this slow the publishing of the numbers.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 22nd, 2005, 8:49pm
Just a side note on the simulation engine.  I have included an interface which defines a sweep, which can be applied to stage lengths, cycle lengths, initial token balances, or any other numeric quantity whose value has questionable impact on the outcome.  The idea is that by assigning a range of numbers to each of these properties, the simulation will perform a sweep across the full range given, and provide results (at a specified sweep increment and a specified number of iterations per sweep position), ultimately providing a range of results which has surprised me quite a bit so far.  When I was implementing my scheme a few days ago I was sweeping the stage lengths and was expecting the plotted results to look something like a concave parabola - but it was more like a a concave parabola added to a sin wave.

The interface isn't really very versatile yet, but I think it will be a valuable tool in identifying the underlying properties of the schemes.  Coming soon - so don't touch that dial.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 22nd, 2005, 11:41pm

on 03/19/05 at 06:41:07, SMQ wrote:
 Sticking with 10 badgers for the moment (one of whom is also the crowner), I found the following series of badge sizes (used in gypo's stage 0) result in an average runtime (over 10,000,000 trials) of 3426:1st cycle 6 days long, one badge of size 12 awarded (and also the crown)2nd & 3rd cycles 5 days long, two badges of size 11 awarded4th - 6th cycles 5 days long, three badges of size 10 awarded7th - 10th cycles 4 days long, four badges of size 9 awarded.This solution still uses gypo's stage lengths (2000, 1600, 300, 300, ...) which seem to be close to optimum for 10 badges.

Using the gypo's algorithm as described by Icarus I cannot reproduce his numbers (I get close to 3650), and using these numbers I get close to 3600.

In my implementation I have checks to ensure that the number of outstanding tokens + the sum of costs of ready badges + the cost of the light if it is on is equal to 100, i.e. that no stray tokens appear that can speed things up.  Could you post the program you're using?

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 23rd, 2005, 7:28am
In preparing my code for publication ;) I did find one error: it wasn't counting stage 0 days toward the total.  So my tweek to gypo's approach runs in 3473 rather than 3426 as I reported.  Still slightly better (16 days), but not quite as dramatic--oh well.  Anyways, here's the code (in C++; frand(n) returns a random integer evenly distributed over 0 to n-1):

Code:

(edited to change vaiable names to more closely match Icarus' summary)

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 23rd, 2005, 7:29am

Code:

(edited to change vaiable names to more closely match Icarus' summary)

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Mar 23rd, 2005, 8:50am

on 03/22/05 at 20:27:35, Leonid Broukhis wrote:
 Must read "potentially leaving him with a negative token count".

"If he does not have a token..."

If he doesn't have a token, borrowing one is unlikely to leave him non-negative.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 23rd, 2005, 9:04am
A side note: as I've been playing around with various numbers of badges and stages trying to improve on my tweek to gypo's opening to [10,10], it occurred to me that in a final trinary stage, it can be very beneficial for the inactive prisoners to act as observers.

If *anyone* ever sees the light on, then off, then on again they know all three final-stage prisoners have visited the room and can immediately declare victory without waiting for the final item to be picked up.

The same principle can actually be applied to any final stage, but the benefit to stages with >3 items declines rapidly as the chance that any prisoner will have been in a position to observe all drop-offs and pick-ups becomes vanishingly small.  Let N be the number of active prisoners, O be the probable number of observers who witnessed every drop-off and pick-up, and D be the probable number of days saved (all for 100 prisoners):

N   O    D

3   17   94
4   10   90
5   2    50
6   <1   0
(see edit below)

As, if I understood right, rmsgrey pointed out below, if the final leader is already holding one or more items no observer will ever see a full count, which severely limits the utility when applied to anything other than a trinary round, so don't expect to see a 90 50-day savings in a round of four unless you can ensure the leader never starts out with an item...[/edit]

But if the leader doesn't start out with a token my probabilities are too high, and if he is supposed to (as I assumed when calculating the probabilities) but a previous round failed an observer could claim false victory--let's try that again...

N   O    D

3   17   94
4   2    50
5   <1   0

[/edit]

--SMQ
(edited again to ref. rmsgrey below)
(edited yet again to update probabilities)

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Mar 23rd, 2005, 9:21am

on 03/23/05 at 09:04:32, SMQ wrote:
 A side note: as I've been playing around with various numbers of badges and stages trying to improve on my tweek to gypo's opening to [10,10], it occurred to me that in a final trinary stage, it can be very beneficial for the inactive prisoners to act as observers.If *anyone* ever sees the light on, then off, then on again they know all three final-stage prisoners have visited the room and can immediately declare victory without waiting for the final item to be picked up.The same principle can actually be applied to any final stage, but the benefit to stages with >3 items declines rapidly as the chance that any prisoner will have been in a position to observe all drop-offs and pick-ups becomes vanishingly small.--SMQ

That only works if people only collect tokens if their badges are filled - with most final stages, you can never find out what the leader's status is by watching the lights...

[e]
It also requires the rules for the trinary stage to be clear on what happens if previous stages were unsuccessful - if there are two (k-1)-tokens and two k-tokens out there, do people with (k-1)-tokens collect passing k-tokens or not? I'd suggest not.
[/e]

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 23rd, 2005, 9:53am

on 03/23/05 at 09:21:22, rmsgrey wrote:
 That only works if people only collect tokens if their badges are filled - with most final stages, you can never find out what the leader's status is by watching the lights...

Hmm, not sure I followed that.  I can see where, if the final leader has already collected one or more tokens/filled-badges/whatever-it-is-the-final-leader-is-collecting (as is likely in most final stages >3) then no observer will ever see a full count.  It should always work for a final trinary, though, so long as the three tokens start out in unique prisoners' inventories (and if one prisoner already holds two, observers can't shorten the round anyway).  Right??

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 23rd, 2005, 10:06am

on 03/23/05 at 08:50:27, rmsgrey wrote:
 "If he does not have a token..."If he doesn't have a token, borrowing one is unlikely to leave him non-negative.

Oops. Between your and gypo's description, I got the combined rule "if he has a token or a badge, he leaves a token" in my head.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 23rd, 2005, 11:23am

on 03/23/05 at 07:28:36, SMQ wrote:
 In preparing my code for publication ;) I did find one error: it wasn't counting stage 0 days toward the total.  So my tweek to gypo's approach runs in 3473 rather than 3426 as I reported.  Still slightly better (16 days), but not quite as dramatic--oh well.

Thanks. I've found a bug in my code related to stage lengths: it was going 2000, 1600, 2000, 300 by mistake. And I've found a little bug in your code: it overcounts by one day because the loop increments the day number before figuring out that a trial has been completed.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 23rd, 2005, 11:36am

on 03/23/05 at 11:23:59, Leonid Broukhis wrote:
 And I've found a little bug in your code: it overcounts by one day because the loop increments the day number before figuring out that a trial has been completed.

Oops. :-[  I used to have "if (complete) break;" after each possible completion point, but it seemed cleaner to move it to the loop condition...

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 23rd, 2005, 5:22pm
I've changed gypo's badge values to 11, 10...10, 9 and got 3466.48 days (a new record?) over 1,000,000 trials using 2000, 1600, 300, 300 stage lengths. And this is because the average numbers of tokens needed to fill the badges at the end of the snowball rounds for this new scheme is, in order the badges are given out are now:

7.3   6.5   6.7   6.9   7.1   7.2   7.3   7.4   7.5   6.8

(max - min = 7.5 - 6.5 = 1.0), sum = 70.7

In the original gypo's scheme it was
6.3   6.5   6.7   6.9   7.1   7.2   7.3   7.4   7.5   7.8 (max - min = 7.8 - 6.3 = 1.5)

For comparison, SMQ's scheme gives 3471.67 days with average remaining counts
6.6   7   7.4   6.6   6.9   7   6.5   6.6   6.7   7
(max - min = 7.4 - 6.5 = 0.9), sum = 68.3.

With a little lesser disparity and two fewer tokens to collect, SMQ's scheme loses by 5.19 days because its snowball duration is
47 days, compared to gypo's 40 days.

Now it seems that there is a faster way to compare the two schemes by looking at the disparity of the remaining token counts and their total (to find out these numbers, one only needs to simulate the snowball rounds which is about 100 times faster than a full trial). If for scheme A both the remaining count disparity and the sum is greater than in scheme B for the same number of days in the snowball rounds, scheme A is definitely worse than scheme B.

This observation may help mattian in his sweep efforts.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 23rd, 2005, 5:32pm
Okay - Some more numbers:

After 10000 iterations 100 AlexHPrisoners escaped in an average time of 9321.4869 days; a marginal improvement over the SalemPrisoners by about 45 days.

I won't post AlexHPrisoner.java code here unless someone wants me to.  The reason is that I'm rebuilding the interfaces so it's all going to be changing anyway.

Paul Hammond is next.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 23rd, 2005, 5:38pm

on 03/23/05 at 17:22:58, Leonid Broukhis wrote:
 This observation may help mattian in his sweep efforts.

Actually - another nice feature in the engine is that you can define different outcomes.  For example, the 100 prisoners problem is looking for one outcome - that all prisoners have visited the room without question - but for the benefit of analysis it is sometimes useful to define intermediate outcomes which may be declared by the prisoners, such as the end of the snowball round, or whatever.  This allows us to apply a sweep to the snowball round without having to run the rest of the simulation at all - as Leonid is describing.

P.S. I wish I didn't have a real job so that I could spend some quality time on this thing and post the libraries here for general consumption - for any other riddlers with real jobs they wish they didn't have.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 23rd, 2005, 7:12pm
PaulHammondPrisoners did nicely at 10000 iterations, they escaped after 3964.4215 days on average.  Nice and close to the original claim.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 23rd, 2005, 8:14pm

on 03/22/05 at 20:29:51, mattian wrote:
 Icarus, if this is the summary, I'd hate to see the full document.

Sorry about that. I wanted something self-contained, so that when William gets the headers working again, I could link to it in the header, and help new readers to be able to get the meat out of this thread without having to chew through all the gristle. I also wanted to explain methods by a common approach as much as possible, because it makes understanding new schemes easier, and also makes it easier to compare the approaches different schemes make.

I tend to be wordy, but I pushed to get this out because it was taking away my time from other things. If I get up the gumption (don't count on it), I'll see if I can simply the thing. I may also make some formatting changes to improve readability. One problem I had was that I knew it would be too big for a single post (I didn't expect it to take so many though - the max post size on the new YaBB is really small for someone like me). So I composed the whole thing in a word processor, then cut and pasted to post the pieces. This meant I could preview while posting to see what things looked like.

on 03/23/05 at 09:21:22, rmsgrey wrote:
 That only works if people only collect tokens if their badges are filled - with most final stages, you can never find out what the leader's status is by watching the lights...[e]It also requires the rules for the trinary stage to be clear on what happens if previous stages were unsuccessful - if there are two (k-1)-tokens and two k-tokens out there, do people with (k-1)-tokens collect passing k-tokens or not? I'd suggest not.[/e]

I believe SMQ is talking about the leaderless trinary stage I described. No one can pick up a final-level token unless he also has one. So anyone who sees the light on and then off knows that somebody now has 2 final-level tokens. He also knows that this person will not be passing either token. So if he sees the light on a second time in the round, it has to be the 3rd token being passed, thus guaranteeing that all three have been formed, and everyone has visited.

It is a neat little accelerator for this special case. It might even be considered a special case of that hybrid scheme you and I have been wanting.

---------------------------------------

Excellent work to SMQ and Leonid for the increased times, and to mattian for all the values on the old schemes. I will try to update the summary with them soon.

Title: Re: 100 prisoners & a light bulb
Post by Ronald Waclawski on Mar 23rd, 2005, 9:49pm
I think I finally got this one.

The Light is in the off position to begin with.

1 Prisoner is chosen as the leader.

The other 99 are instructed to Turn ON the light when they enter the room IF and ONLY IF
A: The light is off
B: They have never turned on the light before.

Whenever the Leader enters the room, if the Light is ON the leader turns it OFF.

After the leader turns OFF the light 99 times, he can assertain that the other 99 prisoners have been inside the room at one point or another, including himself.

I'm 99.9% sure this is the correct answer

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 23rd, 2005, 9:57pm
Ronald,

That is certainly one of them, but it will take your prisoners about 30 years to escape.  It is possible to do it in just over a third of that time.  Pay close attention to the posts on pages 19, 20 and 21 of this thread for some alternative solutions.

on 03/23/05 at 20:14:23, Icarus wrote:
 Sorry about that... ...I tend to be wordy, ...

I was only joking about it being long.  It's really not bad if one considers that it's 20 pages and three years worth of posts.

I haven't submitted AlexH2Prisoner yet because his improvement on PaulHammondPrisoner is a little unclear.  He says that an optimisation would be to have shorter cycles subsequent to the first but he doesn't provide any numbers.  We can therefore not associate any fixed results with his optimisation.  The best I can do is to have the AlexH2Prisoner do as AlexH suggests but keep all cycles the same length as the first.

Alternatively, I'd welcome some feedback as to how we should derive subsequent cycle durations in order to find a number we can confidently say corresponds with AlexH's second entry in Icarus' history of key contributions.  We wouldn't want to give AlexH any more or any less credit than is due to him on account of his idea.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 24th, 2005, 5:47pm
You will notice that for some time they didn't really bother to give the stage lengths they were using. This does indeed make it hard to reproduce their results. But you will note that they also did not quote any hard figures. They were trying to find the optimum stage lengths for the given scheme.

AlexH in particular was mostly just suggesting at this point, rather than creating a hard scheme. He noted that later repetitions of the stages could work as continuations of the original stage, rather than starting over as Paul Hammond originally suggested. With this change, it was also clear that there was no longer any reason for later stages to be the same length as the originals. So he also suggests shortening the stages. It was only later, after he suggested and played with the binary scheme, only to discover it's shortfall, that he returned to Paul's [10, 10] scheme and made attempts at it. But again, he was more interested in the theory and his O( )  estimates than actual values.

I would suggest that some sort of optimization scheme would be useful. Can we discover some general principles that apply to optimizing individual stages so that combined they result in an optimized total? AlexH and James Fingas were doing some of this at one point, but I am wondering if their methods were all that effective, since SWF was able to shave an additional 250 days off the best times they came up with for the leaderless binary scheme. Perhaps he might be willing to discuss his optimization techniques.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Mar 24th, 2005, 6:19pm
Well I could run the AlexH2Prisoner through the sweep interface and establish desirable repeating cycle lengths, but it will take me some time to polish up the sweeper - I haven't had much time to work on it.  I'm keen to get it working nicely, if you guys will be patient with me.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Mar 24th, 2005, 8:43pm
I was able to bring the numbers down to around 3459-3460. I cannot quote a more accurate number because even the runs of one million tries with same parameters report averages that differ a lot, e.g. 3457.93, 3462.77, 3459.41. Therefore it is no surprise that graphing the million run averages will result in a seesaw, e.g.
varying the duration of the long token collection phase may yield

1958 3460.45
1959 3459.81
1960 3460.91
1961 3459.82
1962 3460.63
1963 3461.92
1964 3460.01
1965 3461.16
1966 3460.25
1967 3459.71
1968 3460.99
1969 3459.28   <---  minimum
1970 3460.09
1971 3460.82
1972 3460.86
1973 3460.19
1974 3459.65
1975 3461.44
1976 3459.8
1977 3462.03
1978 3461
1979 3461.91

days: 5,  4,  4,  4,  4,  4,  4,  4,  4,  3
cost: 12, 10, 10, 10, 10, 10, 10, 10, 9,  9

Title: Re: 100 prisoners & a light bulb
Post by Jim Harvey on Apr 24th, 2005, 8:19pm
I'm not sure if this was posted, but I don't feel like reading 17 pages of replies, but I think they should break the light bulb in the living room, and using your sense of touch, figure out how many people have visited.

You agree on a corner in which to set the pieces, such as the right hand corner from the door. Now the light bulb will be broken into seven pieces and lined up to touch the wall so you can use your hands to tell when you've come to the edge to make sure no one steps on the pieces.

Now they will be laid out to represent a binary system where if the glass feels convex over the floor, then it equals a 1, concave equals a 0. So if it's your first visit, you can go and see how many have visited before you, if it reads 1100011, that means 99 have visited, and you can go free, if not, increase the number by one.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Apr 25th, 2005, 8:38am

on 04/24/05 at 20:19:58, Jim Harvey wrote:
 I'm not sure if this was posted, but I don't feel like reading 17 pages of replies, but I think they should break the light bulb in the living room, and using your sense of touch, figure out how many people have visited.You agree on a corner in which to set the pieces, such as the right hand corner from the door. Now the light bulb will be broken into seven pieces and lined up to touch the wall so you can use your hands to tell when you've come to the edge to make sure no one steps on the pieces. Now they will be laid out to represent a binary system where if the glass feels convex over the floor, then it equals a 1, concave equals a 0. So if it's your first visit, you can go and see how many have visited before you, if it reads 1100011, that means 99 have visited, and you can go free, if not, increase the number by one.

Without re-reading the entire thread myself, I'm not certain, but I believe that that is a new variation. Previous "physical-token" solutions used 100 distinct tokens rather than minimising the number of tokens.

Yours is also the only "break the bulb" suggestion to take account of the lighting problem.

On the other hand, the main thrust of the thread so far has been to explore solutions when prisoners can only communicate by encoding one bit in the state of the switch. Yours is certainly the best "off-topic" solution so far, but it isn't really what thse who have contributed most to this thread have been looking for.

Title: Re: 100 prisoners & a light bulb
Post by The.coG on Apr 26th, 2005, 9:41am
who wrote the riddle and wont they just tell the answer?
f**** hell im not going to be able to sleep!!

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Apr 26th, 2005, 10:36am

on 04/26/05 at 09:41:36, The.coG wrote:
 who wrote the riddle and wont they just tell the answer?f**** hell im not going to be able to sleep!!

As far as I know, the "best" solution to this one is still unknown.

The simplest solution is [hide]for one guy to turn off the light whenever he can and everyone else to turn the light on once - the guy turning the light off keeps count[/hide]

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Apr 26th, 2005, 4:37pm

on 04/26/05 at 09:41:36, The.coG wrote:
 who wrote the riddle and wont they just tell the answer?f**** hell im not going to be able to sleep!!

You'll find a summary of the solutions provided up to that point here (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=375#382). The best time so far is the 3460 day (on average) solution provided by Leonid Broukhis earlier on this page.

William stated sometime back that when he posted this puzzle, his solution was the Single-leader-with-snowball-round approach that Simon suggested. Paul Hammond's multi-stage concept, which cut times by nearly two thirds, was a surprise to him.

Title: Re: 100 prisoners & a light bulb
Post by Joshua Franco on May 1st, 2005, 9:05pm
I'm just laughing at the whole '~364-something' day scheme because, well, that light's gunna go out, and they'll all be screwed. I think the 'creator' wanted something out-of-the-box like the binary token solution above. I really like that one, and I love when problems can be as true to life as possible, and a bulb lasting more than 9 years with the frequency of use presented isn't that doable.

Now, don't take me as a party-pooper, I'm very interested in what the rest of you are doing, and I'd love to jump in, I'm just casting my vote for the one I mentioned. First: What's the snowball round?

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on May 2nd, 2005, 3:45am
It doesn't matter how long a bulb can last.  It will get replaced.  Or not.  The important thing is whether the switch is up or down.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 2nd, 2005, 7:29am

on 05/01/05 at 21:05:16, Joshua Franco wrote:
 First: What's the snowball round?

Somewhere around Icarus' summaries, I posted a list of definitions.

A snowball round is a period of consecutive days where the light is left on as long as new people keep visiting - it has the potential to accumulate a fairly large count very quickly early in the process, but, since a repeat visit by any prisoner stops the count from accumulating, and the rest of the round is then dead, it's rather less useful later.

Title: Re: 100 prisoners & a light bulb
Post by paul schmitz on Jul 1st, 2005, 7:26pm
i just read all the posts and my hat is off to anyone who came up with a good solution.  i'd like to see some theory regarding a proof to the most optimal solution.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Jul 2nd, 2005, 8:21am
Then you will just have to learn to live with unsatisfied desire!

It is doubtful that even the extremely clever approaches that have been suggested here are optimal. And even given a good approach, it is highly unlikely that you could show no other means could do better.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Jul 3rd, 2005, 12:58pm
Though any significant progress towards an optimality proof would probably be worth the effort of producing. It's extremely unlikely that the techniques of such a proof would fail to illuminate other problems.

Title: Re: 100 prisoners & a light bulb
Post by David Medus on Jul 23rd, 2005, 2:33pm
This might have been thought of...  not a math related answer and is kinda cheating but the rules said nothing about not doing this --> First prisoner breaks the bulb and picks up all but 99 pieces of the shattered glass, then all the prisoners that follow pick up only one piece of glass.  When all but one piece of glass is gone that prisoner knows he is the last.  i know this is cheating but we are talking about life and death here.

Title: Re: 100 prisoners & a light bulb
Post by Three Hands on Jul 23rd, 2005, 5:33pm
Various methods along those lines have been suggested, and the "think outside the box" method is certainly not one to be ignored. However, this thread is still looking for a more maths-orientated solution - part of the reason you won't find me posting on here much.

Feel free to take a look through the development of this topic, as it does make for interesting reading over the ingenuity of various people, both for the mathematical problem-solving, which has been one of the sources of this thread's success and the more abstract reasoning, much more akin to the kind of solution you have offered.

Title: Re: 100 prisoners & a light bulb
Post by Zar on Aug 16th, 2005, 12:57am
1 day on the VERY first day a prisoner, any prisoner can actually claim he and the other 99 have in fact been in that center room

since, to actually get into that court yard, outside a the prison, they would have all infact had to exit their cells

since cells tend to have 1 entrence and exit, thers no other way to get in that court yard, without going through the center room

*see diagram attached

Signed

Matthew McCay

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Aug 16th, 2005, 4:08am

on 08/16/05 at 00:57:35, Zar wrote:
 1 day on the VERY first day a prisoner, any prisoner can actually claim he and the other 99 have in fact been in that center room since, to actually get into that court yard, outside a the prison, they would have all infact had to exit their cells since cells tend to have 1 entrence and exit, thers no other way to get in that court yard, without going through the center room *see diagram attached Signed Matthew McCay

Unless, for example, you have the cell-block as a ring with the central room in the enter, the corridor surrounding, and cells outside that, or any of several other possible arrangements - while the cell block will generally have just the one entrance/exit, that doesn't mean that you have to go through the showers (say) to get to the cells...

It's quite plausible that the chosen room is actually off a corridor (if not, the authorities wuold probably have chosen another room for the purpose - or Mensa's really letting its standards slip!)

Title: Re: 100 prisoners & a light bulb
Post by mattian on Aug 16th, 2005, 7:26am
One day soon - when I'm not working 16 hours a day on my current project, I will finish what I started during the last high-energy cycle of this riddle - the various simulations under one unified engine that will add credibility to the different solutions, and in some cases show them up as the fraudulent works they are (my proposal will probably be a member of the latter group).   In the meantime let's just be satisfied with the solution that the prisoners were all given a key to their cells and every other door separating them from their freedom.  After all, we're ignoring the most fundamental technique to problem solving - contriving an environment that trivialises the solution.  I'm all for being open minded for the purposes of brainstorming and thus allowing everyone to put in their two cents no matter how ridiculous their ideas may seem, but I think there are limits that should be imposed on this flexibility.  One has to ask oneself, why have the problem in the first place, if some reengineering of the factors can illiminate the need for a solution?  Here's an example:

Q: What is 2 + 2?

A: I don't know but if you had asked what 1 + 2 was, the answer would have been 3.

A: Who needs mathematics anyway?

A: That's racist.

Title: Re: 100 prisoners & a light bulb
Post by Zar on Aug 16th, 2005, 10:24pm

Quote:
 Unless, for example, you have the cell-block as a ring with the central room in the enter, the corridor surrounding, and cells outside that, or any of several other possible arrangements - while the cell block will generally have just the one entrance/exit, that doesn't mean that you have to go through the showers (say) to get to the cells... It's quite plausible that the chosen room is actually off a corridor (if not, the authorities wuold probably have chosen another room for the purpose - or Mensa's really letting its standards slip!)

often is puzzles they add a 'factor, that is in fact useless, in this one the light bulb is useless

secondally, as you saw everyone automatically goes for the hardest posible soultion most people are thinking inside the box, of the puzzle, the whole ide of menza is to get people who think outside the box in, and keeping, the 'inside the box' people out

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Aug 17th, 2005, 1:04am
But in this case, thinking inside the box is much more interesting than thinking outside of the box.

The easy way out has been proposed before and isn't worth more than a couple of messages.  The hard way has lead to a number of creative solutions, and a discussion as to which is better.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Aug 17th, 2005, 4:03pm
Actually, Zar, your 'solution' is not "thinking outside the box". Thinking "outside the box" is coming up with solutions such as "first prisoner breaks bulb and leaves 99 pieces. All other prisoners take one piece on their first visit. when all the pieces are gone, everyone has been there". (For the record, this particular solution has been suggested at least 10 times. Numerous other "leave/take something to inidicate your visit" solutions have also been given.)

Your 'solution' is more "reinterpreting the problem to my liking". And it (and variants) have also been suggested many, many times.

It is true that for many problems, coming up with "outside the box" solutions shows creativity and intelligence. But this is not the case for this problem. "Outside the box" solutions are fairly trivial and easy to find. "Inside the box" solutions require much ingenuity and creative effort to devise.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Aug 17th, 2005, 4:07pm
Grimbal,

I don't think with this problem, that thinking inside the box is any more interesting than thinking outside the box - I think the real solutions that have been proposed thus far have incorporated a good deal of out-of-the-box type of thinking.

I think it is a matter of our individual interpretation of creative thinking.  There is a difference between being creative in the context of a problem and being completely arbitrary.  In my opinion, the fabrication of solution-trivialising factors is not creative thinking... it's problem avoidance.  An open minded approach to problem solving encourages creative thinking in order to solve the problem - not avoid it.  It is a different means to the same end.

The reasoning in a solution should make sense no matter which side of the box you're on, and too many of these "right-brained" solutions introduce speculations as fact in order to satisfy their solution.  Such as suggesting that the prison has a particular shape, or that the bulb is within reach and can be broken into 100 pieces.  While these things may be true, there is no information provided which would inform us of them.

Another point to note is that real right-brained solutions are rare and usually elegant - the so-called outside-the-box solutions provided in this thread have been the most common suggestion by new comers - are they all thinking outside the box and shocking us all with their insight?

I may as well say "BLAH" to any puzzle given to me and claim that my response is valid as it is the result of my thinking outside the box.

Title: Re: 100 prisoners & a light bulb
Post by shanky on Aug 24th, 2005, 12:45pm

the courtyard and living room are same room.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Aug 24th, 2005, 1:37pm
You know, I think Shanky is right.  All jokes aside, there was some discussion earlier in the thread where William had mentioned that he didn't know the true origin of the riddle or what the expected answer was or even if there was one.

Despite the fact that our investigation into the statistical solutions have proved more interesting, I have to believe the riddle was originally developed with Shanky's (and the 500 others with the same answer) as the correct answer.

Any new comer to the discussion who hasn't read the thread and answers definitively has stated without uncertainty that the solution is that the two rooms are in fact the same.  Uncorrupted by this thread and having heard the riddle before and its answer, it must be the original intended answer.

Any thoughts?

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Aug 25th, 2005, 9:02am

on 08/24/05 at 13:37:40, mattian wrote:
 You know, I think Shanky is right.  All jokes aside, there was some discussion earlier in the thread where William had mentioned that he didn't know the true origin of the riddle or what the expected answer was or even if there was one.Despite the fact that our investigation into the statistical solutions have proved more interesting, I have to believe the riddle was originally developed with Shanky's (and the 500 others with the same answer) as the correct answer.Any new comer to the discussion who hasn't read the thread and answers definitively has stated without uncertainty that the solution is that the two rooms are in fact the same.  Uncorrupted by this thread and having heard the riddle before and its answer, it must be the original intended answer.Any thoughts?

If you assume the mention of Mensa membership for the prisoners on their release was an incidental corruption, then it's plausible that the originally intended answer was "They've all been in the room already." (While I don't think much of Mensa generally, I don't think that demonstrating the ability to recognise a room would be sufficient for membership)

On the other hand, friends of mine have encountered this puzzle or variants previously under circumstances that make it quite clear that the intention is to require a more mathematical solution.

It's quite possible that there are actually two (now) separate family trees for riddles of this type - one expecting the trick answer; the other looking for the mathematical solution.

The fact newbies are showing up with variant forms suggests that the puzzle is relatively popular, so it's quite plausible for it to have split.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Aug 25th, 2005, 9:26am
I agree with you, but one thing to note is that the mathematical riddles of this type are generally solvable in finite time - not that it should necessarily be that way, but in general it is.  The puzzles with trick-type solutions tend to create an impossible problem that can only be solved by means of said trick.

A good example of the latter is the three light bulb, three switch problem:  Presented with three switches in the off position, fiddle with them appropriately and then visit the adjacent room containing three previously unseen light bulbs and state which switch is connected to which bulb.  Mathematically, this is unsolvable - the practical ("trick") element is the saviour here.

I agree with your perspective on Mensa, precisely because there is a tendency to consider these trick solutions as outside-the-box type, right-brained thinking, which, though valid at a fundamental level, become nausiating as manifestations of self-attributed intellectual credit.

In short: I don't believe that this riddle's original author had any intention of creating a puzzle warranting the sort of effort that the members of this forum have put into its solution.  This puzzle created itself in response to a growing irritation with an inundation of "creative", outside-the-box solutions.  I think the original problem was one with cleverly chosen wording that went something like this:

100 prisoners are assembled in a rooml of a prison where they are given instructions by the warden.  The warden says, "Starting tomorrow, I will pick one prisoner per day and bring him to this room where he will be allowed to operate this light switch ... BLAH BLAH ... when any one prisoner can say with certainty that all of his fellow inmates have visited the room at least once, you will all be set free.  QED.

Title: Re: 100 prisoners & a light bulb
Post by towr on Aug 25th, 2005, 1:17pm
I know this problem from a course in automated reasoning (theorem provers and model checkers). One assignment was to give and prove an algorithm that solved the prisoners and a lightbulb problem; under the assumption of fairness (i.e. every prisoners gets infinitely many turns to enter the room over the course of infinite time).

Such an algorithm was all that was asked here. But after several were given it became a quest to find the fastest; which is a different, much more difficult problem.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Aug 25th, 2005, 3:52pm
I am sure that this riddle was originally intended to be of a mathematical/logical nature, not wordplay or trickery. I am also pretty sure that the original intended answer was the "Leader" solution, possibly with starting "snowball" round.

Certainly, we know (because he said so) that William posted it here to be that sort of puzzle, and his intended solution was "Leader with snowball". The existence of better solutions took him by surprise.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Aug 25th, 2005, 4:02pm
I'll take your word for it.  And besides, I concede that the originally intended puzzle is irrelevant in the current context of the problem anyway.  None of us would have had any interest in the puzzle had it been anything other than what we deem it to be.  It just seems odd to me that this puzzle is so much more popular than all the others by (orders of magnitude).  Are there any other optimization puzzles of this sort in the forum?

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Aug 25th, 2005, 6:01pm
There are few others. Until this last year, the 0.999... threads had more posts. But that one died off and this one underwent a new spat of activity after being almost completely dormant for some time. This isn't surprising, as this thread still has things to discover, whereas the other merely introduces the uninitiated to a well-established fact.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Aug 25th, 2005, 6:11pm
I haven't seen the 0.999 puzzle, but I assume it is the 0.999... = 1 thing.

We need some more puzzles without concrete solutions.  Anyone care to author puzzles without solutions?

I've tried, but you guys have them all solved within three posts.  And the contributed solutions are more elegant than my own anyway.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Aug 30th, 2005, 4:26pm

on 08/25/05 at 18:11:04, mattian wrote:
 We need some more puzzles without concrete solutions.  Anyone care to author puzzles without solutions?

I seem to remember a thread or two about the hypothetical "God Algorithm" for Rubik's Cube - which never achieved anything like the popularity of this thread - possibly because the Cube results were reported rather than derived.

Another reason why this thread has been so popular is the dual nature of the problem - most "open" problems require "difficult" solutions. The hundred prisoners offers solutions at every level, from "easy answers" like "break the bulb and use the pieces" through to heavily abstracted token exchanging methods via the relatively simple "single leader" solution. As a result, the thread has been more or less constantly at the front of the forum and consequently stayed very much on people's radar...

Title: Re: 100 prisoners & a light bulb
Post by raven on Aug 31st, 2005, 5:42pm
I'm by far no mathematician, but I am still working on it. I did have a decent solution once, but having read the whole bloody thing realized it was not original or optimized.... nor the best time, but it was better than the leader solution.

;)

Title: Re: How to Solve 100 prisoners & Light bulb?
Post by Nasta on Sep 3rd, 2005, 2:16pm

on 07/29/02 at 02:05:34, johnP wrote:
 Heh, I'm no expert, but these are my thoughts on the subject:1) There's no way to make sure all the prisoners will be picked by the warden. No matter how many years pass, you can never be 100% sure all the prisoners get picked.

wrong, there is, that is why the bulb is there, to form some kind of a trigger. if the trigger does not go off, then the prisoner can be sure that someone has not yet been to the room. so yea, all the prisoners may not be selected, but then no one will claim that they have been.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 4th, 2005, 11:28am
johnP (who probably doesn't visit this forum anymore) was refering to the fact that there is no guarantee that any particular prisoner will ever be picked. No matter how many days have gone by, there is a small, but still non-zero, probability that at least one prisoner has never been picked to go into the room (if there wasn't, then the problem would admit the very easy solution of simply waiting for the probability to drop to zero).

All the bulb does is provide a means for prisoners to communicate their visits to the room to other prisoners. It does not in any way guarantee that they will each get to visit at all.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 4th, 2005, 12:36pm
JohnP's statement is open to interpretation.  On the one hand it looks like he's saying that probability does not GUARANTEE that all prisoners will be selected in finite time.

On the other hand, it looks like he's saying that no prisoner can say with 100% certainty that all prisoners have been selected even when in fact they have.

I believe Nasta understood it according to the latter interpretation.

Title: Re: 100 prisoners & a light bulb
Post by Nasta on Sep 6th, 2005, 5:48am
sure, there's probability that a fair coin will forever and ever go only heads and it's probably close to that probability. but that's not the point. unless the time comes that EVERYONE has been in the room, the system that the prisoners have formed beforehand will not trigger and the leader(or whatever the system looks like) can be sure 100% that at least one prisoner has not yet been in the central room. so that's not a problem. after all i believe the solution will not be exact with respect to time, but will be 100% exact with the respect to the confidence that all the prisoners have visited the central room. so e.g. if the optimal solution is for example around 10 years(just guessing), there is still probability, however small, that this period is 1000000000 years, and there's probability, also as small that the period is 100 days...the one thing that must be known for sure is that everyone has been there, that, given thanks to the system they use.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 6th, 2005, 5:58am

on 09/06/05 at 05:48:15, Nasta wrote:
 the system that the prisoners have formed beforehand will not trigger and the leader(or whatever the system looks like) can be sure 100% that at least one prisoner has not yet been in the central room.

Not quite true - After day 100, a prisoner can not say for certain that at least one prisoner has NOT visited the room.  All prisoners may have been selected by day 100, but the process will continue for another few thousand days anyway.

But we know what you mean.

If (time_comes)
{
declare_with_certainty
}
else
{
wait_an_eternity
}

Title: Re: 100 prisoners & a light bulb
Post by towr on Sep 6th, 2005, 7:09am
The usual specification of the problem includes that there is fairness. I.e. that every prisoner would be led to the room infinitely often, [forall] t: [exists] v > t : visit_room(prisoner, v) , (in a welldefined sequences, so not infinite times prisoner 1 followed by an infinite times #2).
So then the process can't stall, and there is no waiting for an eternity (it may just seem that way).

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 6th, 2005, 7:19am
the "waiting_an_eternity" bit was solely in the context of JohnP's statement - that a prisoner will never be 100% certain that all have visited.

Nasta and I are saying - JohnP's statement can only be true IF the prisoners are waiting an eternity.  Because: either a prisoner will claim freedom with 100% certainty... or he will be waiting for the day to do it.  There is no middle ground where, for example, on day 20000, a prisoner arbitrarily claims freedom without being 100% certain.

A quick note on the even distribution of random selection:  This does not ensure that the prisoners don't sit around eternally.  I'm sure there are several poor solutions which will ensure an infinite sentence despite the fair selection.

Title: Re: 100 prisoners & a light bulb
Post by Nasta on Sep 6th, 2005, 11:07am
i don't think that anyone argues that just prisoner one and two will be lead there infinitely often, there's a probability of that happen, but like I said it is close to the probability of a fair coin going heads infinitely many times. but on the other hand, the problem does not guarantee that everyone goes just once in an unknown order, otherwise it would be just plain trivial. the one problem i see is that the system of the leader takes too long, because he must be lead in the center at least 99 times, so that he can be sure that everyone else has been there also. but as the chance of his being there is equal to anyone else being there also, it may take as much as 99 times for everyone to visit the center until it is done. it is pretty sure in this case that even if everyone goes in the center for the first 100 days, there is no way that he learns that. or is there?

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 6th, 2005, 11:12am
There is a possibility he might know after 100 days...

With a snowball round that by luck lasts 100 days, the leader (the first guy in) will walk in on day 101 and see the light still off - indicating that no one has been in the room twice.  On day 101, he can declare their freedom.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 6th, 2005, 5:58pm
There is no disagreement from anyone here who understands the solutions that it is possible for the prisoners to know with complete certainty that everyone has visited.

I just don't believe that JohnP was claiming otherwise. My understanding of his comment was that he was refering to what Nasta calls "not exact with respect to time": that there is no guarantee that everyone will visit in any finite amount of time.

Yes, his comments can be interpreted in other ways (as can all of ours). But I choose to give JohnP the benefit of the doubt and interpret them in the fashion in which they are true, instead of interpreting them to be false, and telling him that he is wrong, even though a true interpretation exists.

This thread, and more generally this entire forum, is filled with poorly explained and incomplete posts that require considerable interpretation to make any sense of them. JohnP's post is clarity itself as compared to some others posted by well-respected members. Unless the poster is still around to defend or explain their post, I believe it is wise to assume a true interpretation for the post when one is possible.

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 7th, 2005, 12:23am
try this solution...

A leader is choosen. His name is Jason.

Only Jason may turn the light on and he does so the first time that he enters the room and counts (1) for himself. Even if the light is on when he enters, he leaves it on and counts (1) for himself.

All other prisoners must turn the light off, but, they are allowed to do this only once.

Jason counts every time that he enters the room and turns the light on. He knows that a prisoner who has not had the opportunity to turn the light off, has turned the light off and is now able to be accounted for. (whether the prisoner has never been sent to the room or if the prisoner has been sent to the room and was not able to turn the light off because a prisoner who was sent in before him turned it off.)

Jason counts the number of times that he has turned the light on. When he reaches 100 including the first count for himself, he knows that all 100 prisoners have been in the room.

This count includes prisoners who went into the room before Jasons first visit because the prisoners are choosen one per day and equally. The riddle does not say that the warden will stop sending prisoners into the room after he has sent the 100th prisoner in.

Any problems with that?  8)  :P

Title: Re: 100 prisoners & a light bulb
Post by towr on Sep 7th, 2005, 1:55am

on 09/07/05 at 00:23:56, thrillseeker wrote:
 Any problems with that?  8)
A minor one.
Not all prisoners can turn the light off on their first visit, because a previous prisoner may have already turned it off. So they should turn the light off if it is on and they've never switched it off before.

Title: Re: 100 prisoners & a light bulb
Post by Nasta on Sep 7th, 2005, 4:48am
let's look at the things backwards - to find the optimal time, i would guess that would be the time that all the prisoners have visited the central room. that process could take from 100 days to infinity, but as someone else has posted already a reasonable time would be 5 years. since the one leader approach is one of perfect information of one inmate, and it's average time is 27 years i would guess that the optimal time ranges from 5 to 27, of course the other methods lowered the time needed for a "perfect information" system to 9-10 years. so the question is - is there a possibility for a still better system to exist that gets closer to 5 years, or there exists some other (higher than 5 years)lower barrier that whatever system is chosen it could not get below it?

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Sep 7th, 2005, 5:09am

on 09/07/05 at 00:23:56, thrillseeker wrote:
 Any problems with that?  8)

A fairly major one - on day 10, when Jason enters the room for the first time, he can't tell whether he's the second prisoner to visit, the 10th, or anything in between.

If he assumes he's the 10th, then there's a possibility his count will hit 100 early. If he doesn't, he may never hit 100.

If yu know the warden isn't going to repeat prisoners until he has to, then you don't need the bulb at all - the prisoner who enters on day 100 can claim freedom without any other data.

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 7th, 2005, 10:29pm
rmsgrey,

It does not matter that Jason does not know whether he is the 1st, 10th, 36th or whatever. The warden will continue to send prisoners into the room forever. So all Jason has to do is count the number or times that he turns the light on.

Actually, he need only count the number of times that he enters the room!! When he reaches 2, all prisoners have entered the room because he is sent in once every 100 days after his first trip in!! All prisoners are sent in one per day and equally!!

(I knew this riddle was flawed)

I suppose that since the riddle does'nt say that the warden will stop sending prisoners in after the 100th has entered, he will continue to send prisoners in forever, one a day and equally.

There is no way that any prisoner can know that the 100th day has arrived because the riddle does not state when the process will begin. If the process begins on the same day that they gather in the courtyard, any prisoner who is not sent into the room on that day will not know that that was the day that the whole thing began. Only the prisoners who were sent into the room  on that day will know that is the starting day, and there is no certainty that one of those prisoners will enter on the 100th day and be able to make the claim.

On the other hand......the riddle does say that the prisoners will be sent in ONE PER DAY. So....on the day following their gathering in the courtyard, all of the prisoners could consider that day to be the first day even if its the 2nd. They would just count 100 days and whoever enters on that day makes the claim!

One problem with that though.....the cells have no windows and are soundproof. So there is now way for the prisoners to count days. They do not know when the sun rises or sets.

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 7th, 2005, 10:39pm
Towr,

That is a good point. I should have stated my solution like this...

All other prisoners must turn the light off, but, they are allowed to do this only once.

Title: Re: 100 prisoners & a light bulb
Post by Nasta on Sep 8th, 2005, 1:14am
i don't think the problem is flawed - your interpretation seems to be though. the prisoners are selected equally at random, but that doesn't guarantee that once someone is chosen, he can't be chosen again! on the contrary - the probability of anyone being chosen any particular day is 1/100, this experiment is one of geometric distribution and it does not have memory; one prisoner may be selected on day one, on day two, after that on day 56, and another may not be selected until day 200...

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Sep 8th, 2005, 4:49am

on 09/07/05 at 22:29:25, thrillseeker wrote:
 There is no way that any prisoner can know that the 100th day has arrived because the riddle does not state when the process will begin. If the process begins on the same day that they gather in the courtyard, any prisoner who is not sent into the room on that day will not know that that was the day that the whole thing began. Only the prisoners who were sent into the room  on that day will know that is the starting day, and there is no certainty that one of those prisoners will enter on the 100th day and be able to make the claim.

OK, if you can't tell which day it is for some reason, then a lot of the more serious solutions proposed in this thread fall apart. Even so, if you can rely on the warden not repeating prisoners until he has to, then not knowing which day it is only delays release by one day. On day 101, a prisoner re-enters the room for the first time, and everyone is released.

If the warden can repeat prisoners any time he feels like it, then the ony way Jason can know how many prisoners have visited before him is by knowing that it's day 1, day 2, day 3 with agreed signals, or a specific later day under specific circumstances and with agreed signals. Other prisoners then have no way of knowing whether they're before or after Jason's first visit (apart from the guy on day 1)

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 8th, 2005, 9:29pm

on 09/08/05 at 01:14:11, Nasta wrote:
 i don't think the problem is flawed - your interpretation seems to be though. the prisoners are selected equally at random, but that doesn't guarantee that once someone is chosen, he can't be chosen again! on the contrary - the probability of anyone being chosen any particular day is 1/100, this experiment is one of geometric distribution and it does not have memory; one prisoner may be selected on day one, on day two, after that on day 56, and another may not be selected until day 200...

To me, equally means that the warden will pick one prisoner per day and not the same prisoner twice before all 100 have visited the room.

Is that not the only way to be equal?

I also assume that after the warden has sent in all 100 prisoners, he must use the same order that he used previously for all 100. If he does not, then a prisoner could be sent to the room twice before a prisoner who entered the room before him. If prisoner #2 is sent into the room twice before prisoner #1 is, then it is not equal.

To me, random means that there is no particular order to the way that he picks the prisoners. But, he must repeat this random order after all 100 have entered the room in order for his choices to remain equal.

You stated...."One prisoner may be selected on day one, on day two, after that on day 56, and another may not be selected until day 200..."

If that is true then there is no equality because one prisoner is sent to the room 3 timees before another is sent in once.

There is a problem with my solution however. The prisoners do not know that the warden is choosing them one per day, equally and at random. So Jason would not have any way of knowing that all 100 of the prisoners have been to the room after his first visit.

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 8th, 2005, 9:45pm

on 09/08/05 at 04:49:26, rmsgrey wrote:
 OK, if you can't tell which day it is for some reason, then a lot of the more serious solutions proposed in this thread fall apart. Even so, if you can rely on the warden not repeating prisoners until he has to, then not knowing which day it is only delays release by one day. On day 101, a prisoner re-enters the room for the first time, and everyone is released.If the warden can repeat prisoners any time he feels like it, then the ony way Jason can know how many prisoners have visited before him is by knowing that it's day 1, day 2, day 3 with agreed signals, or a specific later day under specific circumstances and with agreed signals. Other prisoners then have no way of knowing whether they're before or after Jason's first visit (apart from the guy on day 1)

There is no way for the prisoner sent to the room on the 101st day to know that it is the 101st day. The prisoners do not know that the warden is sending them in one per day, equally at random. Also, the cells have no windows and are soundproof. The prisoners can not count days. They do not know when the sun sets or rises.
A prisoner is sent to the room and then back to his cell. He cannot count the days while he is in his cell. When he is sent in for the second time, 3 weeks, a month, 45 days could have passed and he would have no knowledge of this.

I have a new solution and I will propose it tomorrow. I need to think about it for a day to find a flaw.  8)

Title: Re: 100 prisoners & a light bulb
Post by Nasta on Sep 9th, 2005, 1:26am
equally at random means that every day every prisoner has an equal chance of being selected - 1/100 no matter if he has already been selected once or twice or 100 times...it's not a pseudo random like the function of a winamp...

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Sep 9th, 2005, 5:56am

on 09/08/05 at 21:45:18, thrillseeker wrote:
 There is no way for the prisoner sent to the room on the 101st day to know that it is the 101st day. The prisoners do not know that the warden is sending them in one per day, equally at random. Also, the cells have no windows and are soundproof. The prisoners can not count days. They do not know when the sun sets or rises.A prisoner is sent to the room and then back to his cell. He cannot count the days while he is in his cell. When he is sent in for the second time, 3 weeks, a month, 45 days could have passed and he would have no knowledge of this.

Do the prisoners know how often they get fed?

Yes, it's possible to come up with a means of incarceration that totally deprives a prisoner of any way of measuring the passage of time, but, most of the time, you only bother as part of a torture and interrogation regime rather than for simple containment.

If you can't tell what time it is, then the optimal solution is much easier to determine - as I said previously, most of the "heavy lifting" on this thread revolves around solutions where the day number is significant.

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 9th, 2005, 11:52pm

on 09/09/05 at 05:56:39, rmsgrey wrote:
 Do the prisoners know how often they get fed?Yes, it's possible to come up with a means of incarceration that totally deprives a prisoner of any way of measuring the passage of time, but, most of the time, you only bother as part of a torture and interrogation regime rather than for simple containment.If you can't tell what time it is, then the optimal solution is much easier to determine - as I said previously, most of the "heavy lifting" on this thread revolves around solutions where the day number is significant.

I do not think there is any need for the prisoners to know what # day it is. I admit that I had a misunderstanding of how the warden chooses prisoners based on a one per day, equally at random basis. I believe the solution I provided a couple days ago works fine. With that solution, all prisoners sent into the room before Jasons first visit and after Jasons first visit are accounted for.

The initial state of the bulb is off. Any prisoner sent into the room before Jasons first visit will find the light off. Prisoners are not allowed to turn the light on, so they leave it alone. Those prisoners will have to wait on a future day to enter the room and see if the light is on. If they find it on, they turn it off, and the light is left off untill Jason enters the room and turns it on. Jason counts the number of times he turns the light on. When he reaches 99, he adds one for himself and may then make the claim. There is no evidence that the warden will ever stop sending prisoners into the room, so its safe to say that all prisoners will make several trips into the room, and eventually they all will have a shot at turning the light off and being accounted for. I do not have the math skills to calculate how long that could take.  8)  ;D

Title: Re: 100 prisoners & a light bulb
Post by Nasta on Sep 10th, 2005, 3:59am
that is the one leader approach - the avarage time is 27 years...the most optimal that are discussed are a lot better - 9-10 years, read the whole thread to see them...

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 10th, 2005, 8:45pm

on 09/10/05 at 03:59:17, Nasta wrote:
 that is the one leader approach - the avarage time is 27 years...the most optimal that are discussed are a lot better - 9-10 years, read the whole thread to see them...

Last night I found a fault with this solution. It does not say anywhere in the riddle that the prisoners are disclosed the initial state of the bulb. The riddle only tells you that the prisoners are allowed to toggle the bulb and make the claim that all have visited.

Can the prisoners afford to take a risk like that? Assuming that the initial state of the bulb is off? No, they cant. When Jason enters the room for the first time he will have no idea if anyone was sent in before him. Any prisoner sent in before Jason will  not know if Jason has already visited.

The plan they have decided on assumes that the bulb is initally off. With that in mind, lets suppose that the bulbs initial state is on! (As far as the prisoners know, it very well could be.) Any prisoner that enters the room will assume that Jason has already been in because the light is on and only Jason is allowed to turn the light on. That prisoner will turn the light off and assume that he will be accounted for. Then, when Jason enters for the first time, he will assume that the original state of the bulb was off and nobody has toggled it yet. The prisoner who toggeled it before Jason entered will not be accounted for because he has already toggled it once and cannot toggle it again.

I consider this is a serious threat to all of the solutions that assume that the prisoners know the original state of the bulb.  :o

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 10th, 2005, 8:56pm
The solutions in this thread have tackled that issue.  It's quite simple as long as you know which day the selections will start.  On the first day, the first prisoner entering the room, simply initialises the bulb to the agreed upon state - and then sets it according to the agreed upon strategy.

If on the other hand they do not know which day the selections are to start - and I don't believe this scenario has been covered in this thread - it can be a bit tricky.  Unless, for example they know that selections will begin within some maximum period of time, in which case their escape time will be offset by that amount.

Title: Re: 100 prisoners & a light bulb
Post by thrillseeker on Sep 10th, 2005, 9:29pm

on 09/10/05 at 20:56:06, mattian wrote:
 The solutions in this thread have tackled that issue.  It's quite simple as long as you know which day the selections will start.  On the first day, the first prisoner entering the room, simply initialises the bulb to the agreed upon state - and then sets it according to the agreed upon strategy.If on the other hand they do not know which day the selections are to start - and I don't believe this scenario has been covered in this thread - it can be a bit tricky.  Unless, for example they know that selections will begin within some maximum period of time, in which case their escape time will be offset by that amount.

How does the first prisoner to enter the room know that he is the first prisoner to enter the room? He cant. How can any prisoner know when the first day is? They cant. The first day could be the same day that they are sent to the courtyard to discuss a plan. It could also be the following day. [b]"Before this whole procedure begins, the prisoners are allowed to get together in the courtyard to discuss a plan."[/b]

They do not know when the selections will start, the do not know that selections will begin within some maximum period of time.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 10th, 2005, 9:42pm
Well they MAY not know - it isn't specified in the problem statement.  Or maybe it is - I haven't read it in a while.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 11th, 2005, 12:46pm

on 09/10/05 at 21:29:41, thrillseeker wrote:
 How does the first prisoner to enter the room know that he is the first prisoner to enter the room? He cant. How can any prisoner know when the first day is? They cant. The first day could be the same day that they are sent to the courtyard to discuss a plan. It could also be the following day.

Though the problem does not explicitly say that the prisoners know when the process starts, and how much time is passing, it also says nothing to suggest otherwise, and the general assumption in this thread is that both are known to the prisoners.

If you would like to start a discussion on the situation where one or both is unknown to the prisoners, I suggest starting a new thread for it, rather than diluting this thread with differing cases. (Including discussions of multiple scenarios in a single thread invariably causes confusion as some readers will mistake which scenario applies to each post. I learned this the hard way when I innocently introduced a second interpretation into the "Greedy Pirates" thread.)

The problem with unknown starting times and time passage is discussed in the 2-light-bulb variant, but of course there the prisoners are given an additional resource to help deal with it.

Title: Re: 100 prisoners & a light bulb
Post by Nasta on Sep 15th, 2005, 7:45am
any progess with the optimal numbers of counters, number and length of cycles?
or ways to prove that optimality exists?

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 15th, 2005, 3:18pm

on 09/15/05 at 07:45:42, Nasta wrote:
 any progess with ... ways to prove that optimality exists?

It is highly likely that an optimal solution exists. And if we take the average time for solutions to be rounded to the nearest whole day, then existance is guaranteed.

Proving that particular solution was optimal is another matter. I'm not sure how you could do that.

The best I can see is to find lower bounds for the average solution time that apply to all solution methods. If you can find a method whose average time is also a proven lower bound, then obviously that solution is optimal.

So far, the highest lower bound I know of is the expected time before all 100 prisoners have visited the room (a value I do not know yet). They cannot learn that they have all visited before they have all visited. But this value is probably much smaller than the optimal average release time.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 15th, 2005, 3:42pm
The odds that any given prisoner will not have been selected at least once after 450 days are about 1%.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Sep 15th, 2005, 6:33pm
But with 100 prisoners all those 1%'s add up...  based on around 8 million trials, I get the average number of days until all prisoners have been chosen as 518.65

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Guest on Sep 18th, 2005, 11:35am
Sorry, I haven't read all of the posts (so excuse me if I am repeating someone's arguments). All I can say is the 'leader' solution is absolutely fine, with one exception:
The initial state of the light switch is unknown. Suppose the light switch is initially ON. The leader flips it OFF and raises his count by 1, thus being mistaken. If he counts 99 flips, he cannot be sure all of his 99 fellow prisoners entered the room (he can miss a person).
He needs to count 199 flips, and prisoners must be allowed to turn the light on for the second time too.
With that slight modification, it guarantees 100% success.

This is the desired solution, since the problem clearly says that the prisoner who decides to make the statement wants to be 100% sure he is correct.
Some can argue it can take infinite time, but the problem's conditions imply that everybody visiting the room can also take inifinite time, given that the warden picks the inmates randomly.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 18th, 2005, 11:42am
Guest,

The first person in the room can simply initialise the bulb to an agreed upon initial state.

Title: Re: 100 prisoners & a light bulb
Post by Guest on Sep 18th, 2005, 11:44am
Sorry for double-posting, but I have noticed that Salem's solution has a major flaw:
They decided that the first person who enters the room twice becomes the 'leader'... but how can a prisoner know that he is the first to visit the room twice? AND how do others know that he is the leader (from that moment)?
This approach is wrong, since the prisoners cannot exchange information by any means.
If they could have, the solution would have been reduced to this nonsense:
"When a prisoner enters the room for the first time, he lets the others know, and the 100th prisoner can state with certainty that every prisoner has been in the room."
Which is absurd, since the light switch becomes useless and the solution is trivial.

The bottom line is: nice try, but they cannot exchange information. I am convinced the 'leader' solution above is the correct one.

Title: Re: 100 prisoners & a light bulb
Post by Guest on Sep 18th, 2005, 11:58am
mattian, what you mean is that the first day is devoted to initializing the light switch to OFF. Okay, I agree, but that is acceptable only if they can keep track of time.

I also heard other variants of this problem, where the warden can summon a prisoner whenever he wants (meaning more than a prisoner per day, and also in non-regular time intervals). And what if they don't know what day it is? They cannot exchange info, they are in solitary confinement...

I'd like to think that the 199 count 'leader' solution is more general and is time-independent.

(N.b sorry for tripple posting, really really sorry)

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 18th, 2005, 12:04pm
No - what I mean is that the first prisoner (without having to dedicate his entire visit to initialising the bulb) can enter the room, initialise the bulb to the agreed upon state, and then, during the same visit, set the bulb's state according to the particular strategy.

Title: Re: 100 prisoners & a light bulb
Post by Guest on Sep 18th, 2005, 12:36pm
Combine the first and second day into one, or don't, that's not my point.
My point is that the 199 count solution is general and time-independent and doesn't require the problem to formulate conditions such as:
- The warden must summon one and only one prisoner to his room, every day.

All I'm saying this solution is more general. It is even a solution to the same problem, with more strict rules, like:
- The warden can summon a prisoner to his room whenever he wants (as many prisoners as he wants per day, and in non-regular time-intervals too). Which implies he can decide not to summon prisoners at a certain day.
And those rules only present more difficulties to time-dependant solutions, where prisoners have to count days.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 18th, 2005, 7:14pm
Yes, that is a solution to the more general problem. But as I just pointed out to thrillseeker a few days ago, the discussion in this thread is about the specific problem where the warden chooses exactly one prisoner a day, and the prisoners are able to keep track of days.

Just about every solution in this thread (except the oft repeated trivial "leave a mark" and "the meeting was in the room" solutions) was given with these assumptions, and should only be interpreted in the presence of these assumptions. I.e., you have not spotted a major flaw in Salem's solution - you have just noted that it does not apply to situations other than the one Salem offered it for.

The more specific problem addressed here is quite interesting in its own right. Because the prisoners are able to track days, they have the capacity to greatly reduce their expected release time over that available even under Salem's shortcut (refered to later in the thread as a "snowball round"). Paul Hammond suggested a means to cut Salem's time by nearly two-thirds. To read up on the ingenious solutions offered by Paul and by his successors, you can read through the thread, or else, read the summary I gave starting here. (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=382#382) Note some of the numbers I gave were out-of-date even when I gave them, and there were some improvements since that summary, which you will have to find by reading onward. Mattian in particular has done much to improve our understanding of several of the schemes that I never incorporated. (Also, I fully admit that the summary is not easy reading - I had to do a lot of both condensing, and fleshing out concepts not fully explained when originally posted.)

The situation wherein the prisoners are not picked once a day (or are not able to track days), and wherein they do not know the state of the bulb is also valid, but should not be mixed with this discussion. If you would like to explore it more, I strongly urge that you start a new thread. It has been partially addressed in the "100 prisoners and 2 light bulbs" thread, but as the name indicates, that thread also introduces a second bulb to the situation.

Title: Re: 100 prisoners & a light bulb
Post by mattian on Sep 18th, 2005, 7:28pm

on 09/18/05 at 19:14:28, Icarus wrote:
 Mattian in particular has done much to improve our understanding of several of the schemes that I never incorporated.

Maybe I'll finish what I started with that one day when I'm not working 16-7.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 18th, 2005, 7:46pm
You will notice that I never updated my summary with your new values, like I said I would, either. So I am not about to scold you for not finishing your review!

Title: Re: 100 prisoners & a light bulb
Post by Ed W on Sep 22nd, 2005, 8:57pm
ok people if this is crack pot please let me know, but if I was a prisoner in this situation this is what i would do.
Forget the light switch that helps you none. You have to devise a plan that you can measure. so i propose this.
First, if you can leave things in the room, just have a prisoner leave a shoe, shirt, or something accessable to all prisoners, once you have 100 shoes, shirts, or something else you would know all people have been in it at least once. Obviously if you already left a shoe dont leave another one.
If this option is not available I would turn my attention to the light bulb. I would instruct the other inmates to use the light bulb as a measuring tool. Tell the inmates to start at a wall (North, South, East, or West), then unscrew the light bulb and place it flat on the floor against the wall. Then when the next person comes in have them move the bulb one full light bulb in front of the previous spot. Once you get far enough you should be able to measure how many 'bulbs' away the bulb is from the starting wall, once your 100 bulbs away from the starting point you've got it.
Ok people, tell me what you think, I dont have a fancy math equation to tell how many days it will take but it seems that these two ideas would work. this is what i would do so its the best i got.

e

Title: Re: 100 prisoners & a light bulb
Post by BNC on Sep 22nd, 2005, 9:05pm

on 09/22/05 at 20:57:52, Ed W wrote:
 ok people if this is crack pot please let me know, e

Hi Ed,

This answer is not "crack pot" as you call it, but it was proposed numerous times before. If you can find the time to read through it (rather long) thread, you will find many of this type of suggestions, and the general agreement among the forum regulars that it is more interesting to solve it "within the box" -- with the fancy math. :)

Title: Re: 100 prisoners & a light bulb
Post by Edward Smith on Oct 16th, 2005, 5:44am
I don't think anyone has proposed a solution in n time.  The puzzle page defines 'optimum' as least amount of days, not most number of prisoners.

If each prisoner just claims that he is the 100'th, then on the 100th trial, one prisoner will go free.

Voila, no?

Edward

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Oct 16th, 2005, 9:38am
Not really.  The problem states:

"The prisoner has the option of asserting the claim that all 100 prisoners have been to the living room. If this assertion is false (that is, some prisoners still haven't been to the living room), all 100 prisoners will be shot for their stupidity."

There is only one chance, then the game is over.  I understand this as meaning the claim must be made only with 100% certainty to be true.  This being said, probabilistic solutions have been given in this thread.

Title: Re: 100 prisoners & a light bulb
Post by JocK on May 8th, 2006, 11:52am
The light bulb is a red herring. A perfectly acceptable solution (no secret signaling, no telepathy, no cheating, ...) exists that does not use the light bulb and that:

1) allows the prisoners to make their claim immediately after the 100th prisoner has visited the living room

2) reaches a degree of certainty that is as close to 100% one desires (provided one is willing to increase the amount of preparation).

Will post the solution later...  ;D
(no kiddin' don't want to spoil another - related - thread)

Title: Re: 100 prisoners & a light bulb
Post by ctsio on May 28th, 2006, 3:13am
ok here is the best solution which I have come up with so far.

On the first day, the first prisoner enters the room and turns on the light because it is his first time in the room.

For every day which follows, if a prisoner enters the room and it is their first time in the room then they leave the light on.

After a period of time eventually one prisoner will enter the cell for their second time. Call this person the LEADER. On the day that this happens the LEADER will know how many people have been in so far. E.g if the LEADER is found on day 50 then 49 people have been in the room for their first time. (I.e we don't include the LEADER twice )

From that day forth, if a person enters the room and has already been in there before they do nothing. If a person enters the room and the light is off and it is their first time in the room they turn it on. This signals to the LEADER that a new person has been in the room. If a person enters for the first time and the light is already on they do nothing because that means someone else is already signalling to the LEADER that they have been in the room for the first time.

Basically the LEADER, every time they enter the cell, if the light is on then they add 1 to the tally and turn the light off. If the light is already off they do nothing.

When the LEADER has counted to 100 then they are free.

Title: Re: 100 prisoners & a light bulb
Post by towr on May 28th, 2006, 7:14am
So, what happens when prisoners A,B,C arrive in the sequence
A,C,A,B,C
Wouldn't C as well as A think they're leader?

You could amend it by never switching on the light for the first 100 days (except by the first prisoner), this way there can be only one leader. (As there is guaranteed to be a double, or the last prisoner knows all have been there)

Title: Re: 100 prisoners & a light bulb
Post by alien on May 29th, 2006, 1:44pm
Lend me your ears because I don't have the answer.. I was thinking about this riddle past three days, and come up with nothing.  Well, almost nothing. I remember a riddle about hats, where a group of people buried up to their necks had to guess what color their hat is, otherwise natives would cut their head off. A big part of the answer was odd and even numbers of hats. Being optimistic, maybe that could be applied to this riddle also. Alas prisoners are in soundproof cells, so the only form of communication is the bulb. But I still have a feeling that a bit more information could be passed without choosing the leader, if we consider odd and even, say, days. So prisoners that were already in the living room on odd days press the switch, and on even days don't touch it. And, say, those who are first time in the room press vice versa. Now this plan I just mentioned, doesn't mean anything, or at least I think it doesn't, but it is an example of how one could dare to play with this riddle in search of optimal plan. The idea with odd and even days pretty much revolves around a single day, whether it is odd or even, or a particular day. So on this day, let's say 1000th day, if light is on, that should mean that all 100 prisoners have been to the room. Otherwise they wait another 1000 days to see whether 2000th day is their lucky day. I thought about this, and pretty much quit. Oh well..    :-/  ;)

Title: Re: 100 prisoners & a light bulb
Post by Icarus on May 29th, 2006, 5:01pm
A summary of the methods suggest at the time is available on page 16 starting here (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=375#382). I admit it is not easy reading, but it still beats the heck out of reading through the first 15 pages. It also puts most of the "in-the-box" solutions into a common idiom, which makes it easier to interpret new ones.

Your solution seems to be a variant of the single solution that I did not put in that idiom. Of course, part of why I didn't bother to translate that one was that it was extremely long running.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on May 30th, 2006, 8:34am
Also, the current leader (with an average runtime of 3460 days) is detailed in this post by Leonid Broukhis (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=400#411) which refines this post of his (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=400#402) which builds on this post of mine (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=350#360) which describes a refinement of this post by gypo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=200#202) which is the last method described in Iacrus' summary.

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Sjoerd_de_Vries on Jun 29th, 2006, 2:38am
Hello guys,

I would like to present not a solution but two frameworks that provide a mechanism for the guaranteed optimal solution within those frameworks. I believe that all current solutions without pre-defined roles fit into those frameworks, except the idea of non-equal sized tokens.

The first framework is about token transfer. A prisoner initially has one token. When a prisoner enters the room at day t, and the light is on, he receives an amount of tokens equal to the pre-defined quantity from the previous day, x(t-1). Then, if his current total of tokens is larger than the pre-defined quantity of today, x(t), he turns the light on and subtracts x(t) tokens from his inventory. However, he will not do this if his inventory contains more tokens than y(t). Therefore, a solution can be generalized to a set of x and y values for each day.
It has been suggested before on this forum as a radically different solution, however most solutions are just a special case of this general scheme.
A snowball stage can be easily coded into this scheme by incrementing x(t) by 1 each day while keeping y(t) to infinite, and in a later stage x(t) can be set to v and y(t) to v+1, where v is the amount of tokens that an assistant leader has to collect.

The second framework is about the distributions of tokens. You can sort the number of token each prisoner has from high to low. The initial distrbution is 1, 1, 1, [ 1 ]97 (so 100 x 1), while the terminal distribution is 100,  0, 0, 0, [ 0 ]96 (1x 100 and 99 x 0). There are about 190 million of these distributions, and at any step the current state can be described as a 190 million x 2  matrix. The first element codes for the probability of that distribution to be present, while the second element codes for the probability that the light is on if that distribution occurs.
Now, you can carefully keep track of this matrix and assess the effect of every operation. In addition, you could devise a scoring scheme for each distribution, being dependent on the inequality (the more unequal the distribution, the better), the probability of the light being on, and the amount of tokens that the light encodes (which is the same for every distribution). Once you have done this, you 1. don't need to simulate anymore; 2. can incrementally optimize your solution for every single day, independent of what happens on other days.

So the only thing that needs to filled in is the scoring scheme, which would probably involve some kind of entropy; an information theorist (which I am not) should be able to provide it.

My apologies for this very lengthy post.

Title: Re: 100 prisoners & a light bulb
Post by alien on Sep 5th, 2006, 11:19am
Fellow riddlers. I have but an optimal solution, which works in one day. Little did we know, that one of the prisoners is [hide]Bruce Lee[/hide]. So when they meat in the courtyard, to discuss the optimal solution, he applies his [hide]martial arts, and snaps all their necks. And since he is the only prisoner left, when the warden takes him to the central room with one bulb, he declares that all prisoners have been to the room, and takes the bulb with him as a souvenir.[/hide]   8)

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Sep 5th, 2006, 11:43am
:D

You know, of all of the "thinking out-of-the-box" solutions, I believe this is the first time selecting a leader by preemptively killing the other 99 prisoners has been suggested.

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Sep 8th, 2006, 6:17pm
Alas for Bruce, the warden demands that someone announce when all 100 prisoners have visited the room. And worse, the warden does not bring dead prisoners to the room, so all 100 will never visit. :'(

And worse yet, the prison has hired real guards, who know how to shoot their guns and are quite willing to do so, not hollywood guards who either abandon their guns in a show of machoistic idiocy, or stand around like imbeciles until he finishes off the closer guards. This means Bruce has no chance for escape.

Title: Re: 100 prisoners & a light bulb
Post by flamingdragon on Nov 15th, 2006, 4:34pm
Has an answer been found to this yet and what is it if there has been one?

I don't want to read through 20 pages looking for the answer.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Nov 15th, 2006, 6:32pm
Not just one answer - numerous answers. For "in the box" solutions (which are the most interesting for this puzzle), you can find a linked history of solutions here (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=350#363), and a full summary of the solutions up to that time here (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=375#382).

In the next 2 or 3 pages from the summary are several posts that improved upon the times reported in the summary by tweaking gypo's method mentioned in it. But the improvement was modest.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Nov 15th, 2006, 7:50pm

on 11/15/06 at 18:32:02, Icarus wrote:
 ...the improvement was modest.

Oh. Come. On.  Leonid and I squeezed a further 29 days (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=475#494) out of that algorithm!  That's almost a 1% improvement!

;)

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by flamingdragon on Nov 16th, 2006, 3:40pm
Those are very confusing and complicated, has this one been said yet and would it work:

Screw the bulb. Get each prisoner to make a mark on the wall with his fingernail the first time he enters the room. When there are 100 marks, all of them have been there.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Nov 16th, 2006, 5:14pm
Only about 50 to 100 times.

Title: Re: 100 prisoners & a light bulb
Post by flamingdragon on Nov 16th, 2006, 8:10pm
So would that be a correct answer?

Title: Re: 100 prisoners & a light bulb
Post by towr on Nov 17th, 2006, 1:13am

on 11/16/06 at 20:10:44, flamingdragon wrote:
 So would that be a correct answer?
Well, the room gets painted every so often (every 'public' building has regular maintenance after all). So there's no guarantee that even if they are all brought into the room infinitely often that they'll ever know with certainty that they have all been in there. (For example, prisoner X might only be shown into the room at times just before it's repainted. So the others will never see his mark)

Also, it goes past the intention of the puzzle; but that's never stopped anyone here before ;)

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Nov 17th, 2006, 1:54am
Let every prisonner grab the light bulb with the right hand when entering the room.  When there are 500 fingerprints on the bulb (not counting duplicates), everybody was there.
::)

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Nov 17th, 2006, 7:30pm
The warden put some effort into setting up this "communicate only by the light" scenario, and has only promised not to interfere with that means. I wouldn't put it past him to clean the room between visits - or worse yet, add marks of his own. :o

We've accepted that the "leave a mark" solution is valid before, but frankly, it isn't interesting: you don't get any insight from it.

While the best "in-the-box" solutions (those that communicate only by the state of the light) are quite complex, others are fairly simple:

(1) Complete cycle scheme: break the days into "cycles" of 100 days each. At the beginning of each cycle, the first prisoner makes sure the light is on. Any time someone visits for the second time in a cycle, they turn the light off. If the last visitor of the cycle finds the light on, he knows that everyone must have visited that cycle and declares. This method works, but is extremely slow - taking much longer than the expected lifetime of the universe to finish on average.

(2) Distribution scheme: This one also uses 100-day cycles. Each day of a cycle is numbered from 1-100, and each prisoner is also assigned a number. A prisoner visiting on day N can only turn on (or leave on) the light if he knows that prisoner N has visited. If a prisoner visiting on day N+1 (or day 1 if N =100) finds the light on, he knows that prisoner N has visited. When one of the prisoners learns that all others have visited the room, he declares. This scheme on average takes about 8300 years to complete.

(3) Single Leader scheme: At the meeting, one prisoner is picked as leader. Only the leader is allowed to turn off the light. Everyone else may turn the light on only once, which they will do at the first opportunity. The leader keeps a count - starting at 1, for himself - of the number of times he turns off the light. When it reaches 100, he declares. This method takes a far more reasonable 28.5 years on average to complete.

(4) Single Leader with "snowball round": this was the solution that William Wu had in mind when he posted this riddle. This runs like the single leader solution, but the leader is not picked at the initial meeting. Instead, the first 100 days is set aside as special. The first guy in turns on the light. Everyone who comes in during those first 100 days and finds the light on also considers themselves to have turned on the light. The first guy to come in a second time (on day N) turns off the light and becomes the leader. He starts his count at N-1, since that many prisoners (including himself) have already visited. Anyone coming in during the first 100 days and finding the light off does not turn it on or do anything else. After the 100 days are over, the rules of the single leader method take effect. This shaves about 3 years off the straight single leader method, taking about 25.6 years on average.

The best time so far is about 9.5 years, set by Leonid Broukhis and the ever-humble SMQ. ;)

Title: Re: 100 prisoners & a light bulb
Post by flamingdragon on Nov 19th, 2006, 5:35pm

on 11/17/06 at 01:54:58, Grimbal wrote:
 Let every prisonner grab the light bulb with the right hand when entering the room.  When there are 500 fingerprints on the bulb (not counting duplicates), everybody was there.::)

I'm pretty sure the light bulb isn't big enough to see all the 100 fingerprints and I doubt they are allowed to use finger print detecting equipment or anything, except one thing which just gave me a solution, thanks.

Most likely the prisoners have clothes, so when they get into the room they take off their shirts and throw them the ground, when there are 100 shirts on the ground, the person can declare everyone has been there. ;D

Of course it is essentialy the same as marking in the wall, only more likely to happen since the wall probably isn't markable.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Nov 20th, 2006, 7:24pm

on 11/19/06 at 17:35:47, flamingdragon wrote:
 I'm pretty sure the light bulb isn't big enough to see all the 100 fingerprints and I doubt they are allowed to use finger print detecting equipment or anything, except one thing which just gave me a solution, thanks.Most likely the prisoners have clothes, so when they get into the room they take off their shirts and throw them the ground, when there are 100 shirts on the ground, the person can declare everyone has been there. ;DOf course it is essentialy the same as marking in the wall, only more likely to happen since the wall probably isn't markable.

I think someone already suggested that with some other item of clothing...

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Nov 21st, 2006, 4:15pm
Fingerprints, shirts, marks on the wall, piles of *&^# in the corner, turning the bulb ... all of these have been suggested, and it is very easy to come up with other variations. But all of them assume that the warden or other personel will do nothing to interfere, which is in no way indicated in the puzzle.

On the other hand, the warden has effectively promised not to change the on/off state of the light bulb - making this the only sure means of communication. (As sure as the warden is trustworthy - but if he isn't, then you don't have a riddle.)

Title: Re: 100 prisoners & a light bulb
Post by flamingdragon on Nov 25th, 2006, 6:38pm

on 11/21/06 at 16:15:46, Icarus wrote:
 Fingerprints, shirts, marks on the wall, piles of *&^# in the corner, turning the bulb ... all of these have been suggested, and it is very easy to come up with other variations. But all of them assume that the warden or other personel will do nothing to interfere, which is in no way indicated in the puzzle. On the other hand, the warden has effectively promised not to change the on/off state of the light bulb - making this the only sure means of communication. (As sure as the warden is trustworthy - but if he isn't, then you don't have a riddle.)

He doesn't say he will interfere with anything else either, and exactly, u don't know if he's trustworthy. Therefore both kinds of answers are equally valid.

Title: Re: 100 prisoners & a light bulb
Post by Three Hands on Nov 26th, 2006, 5:10am
Granted, both kinds of answer are valid. However, one kind poses a significantly greater challenge to find and prove a "best possible" answer - there are several variations on the "think outside the box, mark the room/bulb in some way that demonstrates you have been there on that occasion...", and after a while these become dull - sometimes imaginative, but dull. This thread already has several examples of that kind of solution, and I believe has been acknowledged as a reasonable solution on various occasions.

However, by trying to solve the puzzle that is intended to be the one presented, there is a far greater challenge to your logical/mathematical ability and being able to spot workable methods. As has already been shown, several different types of solution are possible, and some are expected to work faster than others. While it is clever in one respect to come up with a "fingerprints, shirts, marks on the wall" etc. type solution, it is clever in a different respect to come up with a solution to the intended problem - and even more clever to refine such a solution to the level it is at currently. I never really got past the "leader" method in my attempts, and I doubt I'd know where to start on improving on current methods.

Similar applies to a lot of the other puzzles on the forums. Although attacking the wording is a useful tool to use when looking for solutions (trust me, having done a philosophy degree, I know all about attacking wordings ;) ) there comes a point where the spirit/intention of the puzzle should be recognised, and different methods of problem-solving begin. Most, if not all, of the board regulars tend to accept that there may be multiple solutions for riddles beyond the "intended answer", but sometimes it's worth trying to find that "intended answer". If the riddle is well designed, that answer will feel like it fits better than others.

Apologies for the rant, just felt it might help...

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Nov 26th, 2006, 11:46am

on 11/25/06 at 18:38:34, flamingdragon wrote:
 He doesn't say he will interfere with anything else either, and exactly, u don't know if he's trustworthy. Therefore both kinds of answers are equally valid.

By that reasoning, the answer "They don't have to do anything, because tomorrow Godzilla will come by, tear off the roof, and eat the warden" is also a valid answer, since the riddle doesn't mention that Godzilla won't.

Because the warden has not said he won't interfere with other means of communication, you are taking a risk by assuming he doesn't. The common understanding for this riddle is that the prisoners do not declare until they are 100% sure that everyone has visited. This is never the case if the communication depends on a means with which the warden is free to interfere.

As for the warden's trustworthiness - the idea that the warden cannot be trusted to follow his word does not make other answers equally valid. What it does is make the entire riddle invalid, as there is no solution with an untrustworthy warden.

Title: Re: 100 prisoners & a light bulb
Post by flamingdragon on Nov 26th, 2006, 2:08pm

on 11/26/06 at 11:46:09, Icarus wrote:
 By that reasoning, the answer "They don't have to do anything, because tomorrow Godzilla will come by, tear off the roof, and eat the warden" is also a valid answer, since the riddle doesn't mention that Godzilla won't.Because the warden has not said he won't interfere with other means of communication, you are taking a risk by assuming he doesn't. The common understanding for this riddle is that the prisoners do not declare until they are 100% sure that everyone has visited. This is never the case if the communication depends on a means with which the warden is free to interfere.As for the warden's trustworthiness - the idea that the warden cannot be trusted to follow his word does not make other answers equally valid. What it does is make the entire riddle invalid, as there is no solution with an untrustworthy warden.

LOL, I love godzilla.  ;D
And that would not be a valid answer b/c the question is how can they be sure everyone has been in there, not how to escape.

And the wardens untrustworthiness wouldn't make the riddle invalid b/c it's just a % chance that the warden is untrustworthy, not a gurantee.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Nov 26th, 2006, 5:47pm
But the prisoners do not declare until they are 100% sure that everyone has been there. If the warden is not trustworthy, they can never be 100% sure.

If you are wondering about the 100% business, it came about because someone pointed out early on that if the prisoners are willing to accept a little bit of risk, they could just wait a couple years and then declare with 95-98% certainty. While a valid point, it too becomes quickly uninteresting.

Title: Re: 100 prisoners & a light bulb
Post by Iceman on Nov 27th, 2006, 4:13pm
Somebody stop this riddle. I can't sleep nights.

* insomnia * Sleepless in Seattle *  poppies will make me sleep * will I dream, Hal? *

Title: Re: 100 prisoners & a light bulb
Post by koonie32 on Dec 8th, 2006, 4:51pm
Lol the funny part is this meeting of the prisoners MUST be going on for a long time if they cant come up with an idea for 4 years lol.. (actually the topic has been longer than that).

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Dec 8th, 2006, 8:29pm
There have been numerous valid solutions posted in those 4 years. The thread keeps going because the question of how to get them out as fast as possible by "in-the-box" means is intriguing.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Jan 12th, 2007, 12:25pm
It seemed to me, the post lenght is limited, so I should divide my initial post to several parts...

Hi, I had known modified problem without knowledge of the visit count. Only the one leader solution seemed to be possible. (Without knowing the initial state, there was small complication ... either
A) counter becames "switcher" and drone can light the bulb only once but only when he have seen it on before.
or
B) drone can light the bulb twice and counter swithes it off 198 times.
Your version of the problem is very interesting ... the optimisation dimension for this random process ...

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Jan 12th, 2007, 12:32pm
I have made some progress before reading whole this thread. There is one optimisation which seems noone have used in the full strenght.
The observers can stop the process. This is especially powerfull when the final stages of the process are binary. The goal is to know that all the initial tokens for the binary stage were created.
Tokens neednot be collected. Each prisoner can maintain a list li. li is the number of tokens that surely left the i-th binary stage. The numbers li are related (li>=2li+1, having a token in stage i+1 means li>=2).
In the top binary stage when the light is on every observer knows half of the tokens left previous levels.
In this observer end approach, it seems to be better to take downward order of phases after initial upward order.
(In stage when token represents 1/4 of tokens, when the light is on, every visitor who knows 1/2 of tokens left stage already receives information that 3/4 of tokens left previous stages ...)
It's very probable that in the stage on level that failed in initial run or in following upward binary stage an informed visitor is found.
... improving the algorithm robustness.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Jan 12th, 2007, 12:42pm
I have run genetic algorithm to find optimal parameters for such a process ... no snowroll and dynamic counter selection vere used yet ...
The most successful "gen" was ... the 16 counters in initial stage followed by binary levels with stage/phase lengths 1/1922, 8/473, 16/416, 32/421, 64/336, 32/187, 16/320, 8/320, 1/320, 8/320, 16/320, 32/320, 64/320, 32/320, ... 67328 attempts gives the average 3583.12.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Jan 12th, 2007, 12:44pm
I am thinking about incorporating initial snowroll phase and better counter selection. I am also thinking about 12 counters with 2-2-3 phases, but it seems to me the visitors method for ternary phase is very unstable.
I suppose the initial snowroll phase and the optimized counter selection can save several tens of days. ... I will work on it next week. ... hoping to break 3400 barrier ;)

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Jan 12th, 2007, 12:49pm
Analytic solutions seemed to be very complicated,
but it seemed to me that dynamic programming can be used successfully to improve choices of phase lengths.  ... I hope after the week I will post much better tuned algorithm.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Jan 13th, 2007, 1:12am
I have reread the best known algorithms sumarized on page 15. The Rezyk one is very nice approach as it ends with one infinit one counter phase ... which removes the bigest disadvantage of too many phases algorithms ... the high cost of phase switch.
I am not sure how the comparison with the any observer stop method will end but I hope my method is better ;).
(sending i+1 level token in rezyk requires 400 days in average so the downward phases take longer time...)

The initialisation in gypo's algorithm surely can be optimized. The penalty for getting two badges is rather high so one should optimize its probability.
Initial snowroll can be used either.

Title: Re: 100 prisoners & a light bulb
Post by guido on Jan 28th, 2007, 11:35am
Hello all,
i arrived on this forum a couple of years ago, looking for a few riddles to spend some time. At that time, i saw this one, but didn't really pay attention.. It remained in a corner of my mind, and yesterday i thought to myself "what was it exactly?" after a little search, i could locate again the page, found the riddle and, since i didn't want to think about it  ;D just came to look for the solution..  :-X

Well, none of those that i read in the 21 pages seemed satisfying to me 8) because:

1) the riddle make no mention of counters, badges, and so on. Assuming that a general rule for solving a well done riddle is that all that is needed is given in the question, the answer shouldn't  add anything (this invalidate also the idea of keyholes or anything else that would allow to see the light)

2) when you think about leaders and drones, you assume that there are "actives" and "passives" prisoners. Now, i think (but it is just my idea) that where the riddle says

", all prisoners are set free and inducted into MENSA"

We are getting a clue that they all need to be active and use their little brains.. :D

So i arrived to this solution, wich didn't seem to have been posted and seems to work. I am not giving an average time because, as you will see, it could be 100 days as well as 100 years. But really, once a prisoner think that all have been in, they have (or else i made a big mess  ;D)

so: we shall split the timeline in 100 days segments, that we'll name "cycles" (c). each cycle takes a value c = (c+1) at the end of the cycle.

In this solution, we have to choose a 100 days cycle because we have 100 prisoners.

beginning:

light is off.

Each prisoner must remember the number of times he entered the room.

Each time a prisoner has been (c) times or less in the common room during the cycle, he leaves the swich as it is. If the light is off, he counts the number of days past  (let us say "DP")since the beginning of the cycle and divided them for the number of the cycle: DP/c rounding down if needed. This way, he will know the minimal number of people that have been in the room at least once before him (minpax). If he has been more than (c) times in the room, and the light is off, he switches it on and count as said before. If the light is on, he does nothing but remember the highest (minpax) he ever came around (if any).

At the 100th day (end of (c)):

-if a prisoner has been in the room for 100 days
(that is, if he is the only one, for the whole cycle) he switches the light off.

-If a prisoner finds the light off, he declares that all have been in.

-If a prisoner finds the light on, and he hasn't been in the room 100 days continuously, he switches it off AND MAKES NO DECLARATION (important  ;) not a joke).

At the beginning of 2nd cycle - 101 day: if the person that enters find the light on: means he is the second ever to enter the room.

If it is off, and he never entered it before, he knows that at least 3 people have been in.  Else, he counts that he is the second entering.

[If he has been in the room 100 days during the fist cycle, enters, finds the light off and think he is the second entering, he is a complete idiot and deserves to be executed. ;)]

From now on, each prisoner must take into account the POSSIBILITY to realize a passage of all of them within the end of the cycle.

That is: if a prisoner has spent 2 days in the room, and knows that 1)there have been at least 2 oher people in the room, and 2) there are yet 99 days to the end of the cycle, then he will consider that the condition is possible and turn the light off (or leave it off if it was already).

Else, he will light the bulb.

In both cases, he will remember the highest (minpax) he came across and discard the other (so, if a prisoner came in the 35th day of the 1st cycle and found the light off, and then comes in the 4th day of the 2nd cycle and finds the light off, he will keep 35 as minpax, and discard 4).

In the case of a prisoner that has never been in the room before, he will take his minpax if the bulb is off, and will do nothing if it is on.

Things are so far quite easy, but they start to get complicated when several prisoners spent more than (c) in the room: in this case, to define things a bit better, we can say:

assume that

(on) is the lightbulb turned on

(off) is the lightbulb turned off

(c) is the cycle number

(minpax) is the minimal number of people that have surely entered the room

(DP) is the number of days past from the beginning of the cycle

(PG) the number of times a prisoner came in the room

and both (prisoners) and (cycle) have a value of 100

then

When  a prisoner finds (off) he will count :

if [(prisoners) - (minpax)] < [(cycle) - (DP)]  then (off)

("<" is lower, isn' it ? :o I'm bad at mats..)

If [(prisoners) - (minpax)] > [(cycle) - (DP)] then
If  (PG) < or = (c) then (off) Else (on)

In all cases, he will check for (minpax) to ensure he has the greatest value.

If a prisoner found (off) but didn't have (minpax) because at the previous passages he always foud the light on, he will directly use

If  (PG) < or = (c) then (off) Else (on)

When a prisoner finds (on), he will do nothing.

This way, when a prisoner (no matter who) arrives at the end of a cycle (the 100th day) with the light off, he can surely declare that all have passed in the room at least once.

As said, i am no good at all in maths, so i reasoned it out with those strange symbols..

Sorry.

I would like to know what people think of this solution..

(and about the spelling, i am no english, but surely everybody already noticed.. ;D ;D )

Guido

Title: Re: 100 prisoners & a light bulb
Post by towr on Jan 28th, 2007, 12:00pm

on 01/28/07 at 11:35:14, guido wrote:
 1) the riddle make no mention of counters, badges, and so on.
Those are just conceptual objects though, only existing in the minds of the prisoners.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Jan 28th, 2007, 2:04pm
Yes - the tokens and badges are not real items added to the puzzle. They are just concepts used to make the schemes easier to follow. These schemes could be (and originally were) explained in terms of rules for when you could turn on the light, and maintaining a count of how many prisoners have visited based on which stage the counters found the light on and turned it off.

For instance, in Paul Hammond's original staged scheme (as amended by Alex H.), days were divided into 2 stages: Stage 1 would last a set amount of time, then Stage 2 would last for it's set amount, then stage 1 comes again, and then stage 2 again, and so on.

10 prisoners are designated secondary counters, and 1 of those 10 is also chosen to be the master counter. During stage 1, all non-counters can turn on the light exactly 1 time (the first time they come in and find it off). Each counter has a count which he starts at 1 (for himself). If he enters the room and finds the light on, and his count has not reached 10, then he turns off the light and adds 1 to his count. Otherwise, he leaves the light alone. He himself never turns the light on in stage 1.

In stage 2, non-counters leave the light alone. secondary counters turn it on if their count has reach ed 10. Only the master counter turns it off. In addition to his stage 1 count which he maintains as a secondary counter, he also keeps the master count of how many times he turns off the light in stage 2. When his stage 1 count has reached 10, and his stage 2 count has reached 9, he knows that everyone has visited and declares it to the warden.

As you can see, there is nothing involved here except the light, and information that people keep in their own heads. Expressing the idea in terms of badges and tokens doesn't mean we've added anything to the puzzle that wasn't already there.

I've not fully worked out how your scheme works yet, but based on what I have seen, and experience with previous schemes, I doubt it will prove any faster that what is already out there. I can tell you right now that the average time for your scheme is much greater than 100 days. It takes a few years before it is even likely that everyone has visited once, and no successful scheme can give an answer before everyone has.

The current best scheme is about 9 years average time until release.

Title: Re: 100 prisoners & a light bulb
Post by guido on Jan 28th, 2007, 3:34pm
hi,
really sorry, in fact i DID make a mess.. :-[

It doesn't even works on 2 cycles under certains conditions.. :'(

Guido

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Jan 30th, 2007, 8:28am
Hi, I have told ... after a week I will post more information about "improved" algorithm. I have spend a week trying to optimize counter methods in general and for general number of prisoners.
I have written 7 pages of "article skelleton", but more questions appear than answers:(.

(Small example ... when recovery phases on k levels are equaly long and all nonbinary, the optimal level order is not 0,1,2,...,k-1,0,1,2,...,k-1,... its beneficial sometimes to choose i and skip levels 0,1,2,...i.
This does not mean the levels would be skipped, it rather mean, the phase lengths will differ)

This unsuccessful attempt to solve problem more in general consumed most of the time so I didn't fine tune the observers method with snowroll and dynamic counter initial distribution for nonbinary 0 level yet.

I will work on it with smaller priority....

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Jan 30th, 2007, 7:32pm
Two more souls lost to this beguiling puzzle! Why, oh why did William have to say "prove your solution is optimal"! :'( :'( :'(

Title: Re: 100 prisoners & a light bulb
Post by Joel on Feb 7th, 2007, 1:44pm
Ok, ive read a bunch of probability theories and stuff about this riddle ( most of which i didnt understand) and heres my solution.

The most common forms of light bulbs are, 100 hour bulbs and 1000 hour bulbs, so...

Every day a prisoner is taken into the room with the light. he looks at the writing on it to see how many hours it will shine for.  Take that number and divide if by 100.   --for example-- a 100 hour light bulb divided by 100 is 1.  if it is his first time in the room he turn the light on for 1 hour then turns it off.  If he has been in the room he doesnt turn it on.  After  all 100 prisoners have been in the room and turned the light on for an hour the 100 hour light bulb will burn out; showing the prisoner that is in there at the time that all 100 prisoners have been in the room and turned on the light for 1 hour.

if its a 1000 hour light then the prisoners leave the light on for 10 hours, so on and so forth.

Title: Re: 100 prisoners & a light bulb
Post by towr on Feb 7th, 2007, 2:02pm
A 100 hour light bulb won't burn for exactly 100 hours and then then burn out. It might last 80 hours, or 120.
There is still one of Edison's original lightbulbs burning somewhere, I think.
You can't really depend on the estimated time a lightbulb will burn. If it lasts too long or too short, they'll never get out.

Title: Re: 100 prisoners & a light bulb
Post by Joel on Feb 7th, 2007, 2:41pm

there are a bunch of counter examples for my answer.

- the light was used before the prisoners were first put in the room; therefore, it would burn out too early and they all get shot

-i guess if it burned for an extra amount of hours ( considering it wouldnt be too many extra --like years-- ) it would still burn out--however if all the prisoners were in there and they stop turngin on the light after 100 hours and it didnt burn out then it wouldnt burn out.

i spend like 3 hours at school during class on this riddle, i cant stand the fact that its all probability and math with no non-technical answer !!!!

Title: Re: 100 prisoners & a light bulb
Post by towr on Feb 7th, 2007, 2:56pm

on 02/07/07 at 14:41:01, Joel wrote:
 i spend like 3 hours at school during class on this riddle, i cant stand the fact that its all probability and math with no non-technical answer !!!!
Well, the probability is just to give an estimate of when they get out.
The important first step is that some day they will get out, and that's purely technical.

Title: Re: 100 prisoners & a light bulb
Post by towr on Feb 7th, 2007, 3:06pm
There is another thread which deal with just 5 prisoners (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_medium;action=display;num=1170120860), you might like that better.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Feb 12th, 2007, 3:22pm
rmsgrey introduced improvement of snowroll prephase in 5 prisoners forum. It seems to me I didn't seen it in this 100 prisoners thread.

3rd day exception ... if the prisoner swithes light off on second day as it is repeated visit, he does not become counter. This is delayed one day.
If the light is off after 3rd visit ... counter was choosen.
It is initialised to 1 with probability 1/n^2, it is initialised to 2 with probability 3*(n-1)/n^2 and snowroll continues with probability (n-1)(n-2)/n^2
(for n prisoners).

For c counters and n prisoners its improvement roughly (n-1)/n^2*(n/c+n/(n-2c)). But as counter initialised with snowroll is expected to have much higher goal then other counters, the risk that it remains the only active counter is high and the improvement tends to (n-1)/n^2*(n/1+n/(n-2c))

Title: Re: 100 prisoners & a light bulb
Post by BobStew on Mar 22nd, 2007, 12:40pm
Each prisoner should take a dump on the floor (being careful not to mess up each others' piles) in *one spot only* the first time he's in the living room. Not able to "perform"? Then it's your duty to bite off a body part and lay it in a nice, tidy spot on the floor. First one to spot 100 piles of dung or body parts (or 99 if it's his first visit) wins the grand prize.

Self - evidently, it's optimal in terms of efficiency. It will indeed get the prisoners into MENSA as soon as 100 prisoners have actually been in the living room (there is no way to make it faster than that without swaying the choosing of which prisoners get to visit the room when), though I'm not sure how well a reputation they would get within the MENSA ranks.. :-/

If they had a tiny bit of wit in their heads, they would have gone for toilet paper (most prisoners today get toilet paper), a piece of cloth or even a lump of food.

BobStew - humble advocate of thinking outside the box

Title: Re: 100 prisoners & a light bulb
Post by Three Hands on Mar 22nd, 2007, 2:14pm
So what happens when the guards decide to clean up the room? Or make it messier?

The agreement only stated that the guards would leave the light bulb in the on/off state it is left in. It says nothing about the state of the room itself...

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Mar 22nd, 2007, 4:07pm

on 03/22/07 at 12:40:34, BobStew wrote:
 BobStew - humble advocate of thinking outside the box

...who has posted yet again an answer of what is by far the most common variety, repeated endlessly in this thread. Indeed, if you read the thread, you will discover that your exact variant has been posted before - more than once, I believe. Though I do admit none of your predecessors bothered to ask what if you couldn't perform, much less suggested self-mutilation as the answer.

And yet once again, I point out that the "outside the box" answer is as uninteresting as it is simple. What is challenging here is to figure out the best way to do this "inside the box".

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Mar 23rd, 2007, 2:02am

on 03/22/07 at 12:40:34, BobStew wrote:
 First one to spot 100 piles of dung or body parts (or 99 if it's his first visit) wins the grand prize.

If has to be his first visit.  Or someone screwed up earlier.

Title: Re: 100 prisoners & a light bulb
Post by sammos on Apr 15th, 2007, 6:54pm
i do believe that it is obvious that any specific prisoner visiting the room should have a count of how many of the 100 prisoners have visited the room on the day of his specific visit(i.e. if each prisoner leaves an article of clothing behind on their first visit, weather it be a shirt or a string left in the far right corner of the room(although each person must leave the same piece of clothing as the next); also, on a regular 60 watt light bulb, the metal of the treads mark easily on paint in which each prisoner leaves a tally mark on the wall or floor on their first visit( but what if the walls are made of cinder blocks, right.)

well, to solve it probablistically, i resorted to the law of union of independent events and it goes like this:
to determine the probabilty of independent happenings you must subtract the probabily of an event not to occur from 1. For a second factor you take the probabilty of the first not to occur multipy it by the probabilty of the second not to occur  and subtract that from 1 and so forth.
to determine any prisoners probability being chosen at random on the first day would be: P=1-(99/100)=0.01 ok
for the second day the the probability for the each individual prisoner is:
P=1-[(99/100)x(99/100)=0.0199

so the probability of all prisoners visiting the room by day 450 would be:
P=1-[(99/100)^450]=0.9891398...or just 98.91%

if you continue, the probability that all 100 prisoners visited by day 500 is:
P=1-[(99/100)^500]=0.993429 or 99.34%

and on the 600th day, the probabilty would be:
99.99759%
which to me are pretty good odds that all 100prisoners visited the room. Six-hundred days is still less than 2 years. you can not find it with 100 percent probability because there is still that uncertainty factor in which one prisoner, or even a few prisoners, may never be chosen; but the odds of that happening decrease with each passing day.
\
if you are asking yourself why i went from a single prisoner's chances to everyones chances kind of segue, the answer is because everyone should have the same chances, but the chance that everyone visits the room by day 1 and 2 are 0; so therefor i chose to leave it at that.

Title: Re: 100 prisoners & a light bulb
Post by BNC on Apr 16th, 2007, 3:23am
Welcome to the Wu::forums board, sammos.

Since it is a long thread, I will give you a short answer: both ideas (leaving mark/closing/piles/whatever behind and using probability) were suggested before.
The thread's has evolved to looking for the best-achievable (not using optimal, as that may be impossible to prove) time, while staying "inside the box" and guarantying 100% success.

Title: Re: 100 prisoners & a light bulb
Post by sammos on Apr 16th, 2007, 5:13am
sorry bout that, im new to this so i didnt read every response to this puzzle in the forum; but thanks BNC for setting me on the right path.
so i figure that dealing with the light switch is the accepted "must" factor in solving this riddle.

probablistically speaking, if i were in that situation, i would take the gamble at any time im selected after a year and a half!

well, i really dont know, and i guess the 9 years average time is best although i still dont know by what method the prisoners used to achieve that solution. can somebody fill me in?

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Apr 16th, 2007, 6:34am
Very roughly, the current best strategy works like this:  every prisoner starts out pretending they're holding a "token".  They can "drop" this pretend token in the common room by turning the light on if they find it off, and can "pick up" a token from the common room by turning the light off if they find it on (meaning someone else has dropped a token.)

The strategy starts out with a set of days (a "round") with some fancy rules that allow more than one token to be dropped and picked up at once (because this is more efficient at the start), and which also assign other pretend objects ("badges" and a "crown") to prisoners who pick up the dropped tokens.  From then on, only a prisoner with a badge can pick up a token.

After that comes a long round where the prisoners with pretend badges each try to collect a certain number of pretend tokens, "filling" their badges.  This round lasts long enough to make it very likely that all the tokens will have been picked up and so all the badges will have been filled.

Finally there comes a shorter round where the one prisoner with the pretend crown tries to collect all the filled badges.  (Badges are dropped and picked up just like tokens, by turning the light on and off.)  If he collects them all, he knows everyone has been in the common room (because they each dropped a token which was picked up by someone with a badge) and can declare victory.  If, at the end of the round, the one with the crown still doesn't have all the badges, it goes back to the previous round to try again.  Eventually, the one with the pretend crown has all the pretend badges (and so all the pretend tokens) and declares victory.

For a quick history of the solutions we've considered, see this post by Icarus (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=350#363).  For a more detailed summary, see this series of posts by Icarus (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=375#382).  The details of just the best solution so far (average time of 3460 days) can be found in the links from this post of mine (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=475#494).

Hope that helps!

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Apr 16th, 2007, 6:42am
The basic idea behind the solution is pretty simple:

Each prisoner turns the light on once, and there's one prisoner who is the only one who can turn the light off. The guy turning the light off keeps track of how many times he does it, and when he's done it 100 times (once for each prisoner, including flipping the switch on then off once for himself) he knows everyone else has been in. This gives a time of around 30 years.

To get it down to 9 years, there are two major refinements:

First, rather than just having one guy doing all the counting, have 10 guys each counting to 10 (plus themselves) or 9 counting to 11 (with one of them counting to 12 instead) or some similar division for some number of days, then have a second stage where each of them that has completed their count turns the light on once and only one of them turns the light off - then have a repeat of the first stage to mop up any prisoners who missed being counted, then a repeat of the second to pass on the remaining completed counts, etc...

The second refinement lies in the process used to select the people counting - the simplest form is to spend the first hundred days with each prisoner leaving the light on unless someone comes in for the second time - at which point they become the leader, know how many people have been in so far, then, after the hundred days are over, anyone who didn't leave the light on earlier turns it on once at the first opportunity. This sort of "snowball" actually works best ending after a shorter time - around 30 days - once a leader has been selected, the rest of the agreed duration is wasted time...

Combining those two refinements, along with some minor tweaks like allowing counters to start with a negative count in order to minimise the chances of any given person having to make a double count, gives an initial 30 day stage, at the end of which 10 (not necessarily distinct) prisoners each have responsibility for accumulating a ten-count, and one of them has the additional responsibility of collecting those completed counts, over two alternating stages.

Title: Re: 100 prisoners & a light bulb
Post by Eigenray on Apr 16th, 2007, 9:06am
I know I wouldn't expect someone to read 545 comments before posting.  So, could a moderator just add the summary to the first post of the thread?

The longer this thread gets, the less likely new posters will read it, making it more likely they'll post the same old things over and over again, making the thread even longer, etc. etc.

[I don't know if this would work (or how well), but if Willy posted from the future, would it always show up at the end?]

Title: Re: 100 prisoners & a light bulb
Post by Aryabhatta on Apr 16th, 2007, 10:01am
Maybe we should just lock this thread and ask people to read the summary first and make a new thread if what they are thinking is new.

Title: Re: 100 prisoners & a light bulb
Post by Leonid Broukhis on Apr 16th, 2007, 10:47am

on 04/16/07 at 10:01:22, Aryabhatta wrote:
 Maybe we should just lock this thread and ask people to read the summary first and make a new thread if what they are thinking is new.

I think adding a note about daily cleaning of the room to the problem statement will get rid of most "out of the box" solutions. Deleting all comments that describe such solutions and the ensuing discusions will shrink the thread at least twice.

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Apr 16th, 2007, 7:48pm
There used to be a header, before the YaBB changeover, that did this. I'm always a little leery of changing people's posts, so I haven't attempted to do modify the first post for the same purpose. Perhaps I should, but I don't have the time to spend on it right now.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Apr 22nd, 2007, 12:51pm
As the thread is alive ... I have returned to implementation of observers method end, improving the initialisation. (Originaly I wanted to compute optimal parameters analytically ... but the time is more valuable). I have just now started genetic algorithm to find better parameters than guessed by me.

Curent average is under 3600 days.
Status:
3598.15 3598.15  3580.36  3580.36  3222  3222
10:0:11,8:1:9,7:1:8,6:1:7,5:1:6,5:1:6,4:1:6,4:1:6,4:1:6,4:1:5,3:1:5,3:1:5,3:1:5,3:1:5,3:1:5,3:1:5|1700,600,350|418,368,354,297,269,282
... first row ... averages of different kinds, experiments count
... second row ... is my original initialisation in format:
snowball len:counter redistribution len:goal,...|
counter phase 1 len, counter phase 2 len, other counter phases len ...|
binary phase 1 len, binary phase 2 len, ..., last binary phase len is repeated.

Binary phases are in up, down, up, down ... order.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Apr 22nd, 2007, 11:46pm
Curent status of the genetic algorithm:
3485.55 3485.55  3553.18  3553.18  1797   1797 10:0:11,8:1:9,7:1:8,6:1:7,5:1:6,5:1:6,5:1:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5,4:1:5,4:1:5,4:1:5,4:1:5|1700,647,350|418,368,340,297,269,282

3485,55 is the average of all runs of genetic algorithm.
The "gen" mostly run is listed.
It was run 1797 times, 3553.18 is its average.

after a while:
3384.03 3384.03  3043.78  3043.78  2174   2174 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1700,601,332|480,362,361,289,269,282 ...
3319.02 3319.02  3022.96  3022.96  2973   2973 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1671,601,426|480,362,361,289,269,282 ...
3276.88 3276.88  3023.94  3023.94  3661   3661 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1671,601,426|480,362,361,289,269,282 ...
3187.40 3186.65  2970.21  2970.21 10616  10616 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1600,554,287|480,362,361,289,269,282 ...
3154.13 3152.12  2971.01  2971.01 13303  13303 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1600,554,287|480,362,361,289,269,282

Now 3154.13 is the average of all runs of genetic algorithm, 3152.12 is the average of still alive gens.

I have expected breaking 3400 days barrier, but it seems I was breaking 3000 days! (Now I am approaching 2910 days, but the gen is not the major one yet). ...

2994.49 2908.78  2918.05  2918.05 22852  22852 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1533,554,376|480,362,361,289,269,282

Damn ... there was a bug introduced ... I should correct it and rerun the algorithm ... so wait for another set of results :(

Results after bug correction:
3616.20 3593.81  3484.97  3484.97   501    501 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1700,601,332|480,362,387,289,269,282 ...
3530.24 3515.05  3504.83  3504.83 21689  21689 7:0:11,4:1:8,4:1:8,3:1:7,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,2:1:6,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5,1:1:5|1671,601,404|480,362,361,266,269,282

I have run whole genetic algorithm once again getting folllowing result:
3534.42 3483.64  3482.73  3482.73  2904   2904 8:0:11,5:1:8,4:1:7,4:1:7,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,2:1:5,2:1:5,2:1:5,2:1:5,2:1:5|1717,695,529|480,362,415,289,208,311
There may be better parametrization ... different periodical len for downward phases, upward phases and the top phase, but I expect only small changes in average len. The snowballs parameters pattern ... always the same difference between the goal and snowball len may also not be optimal.

I don't know details of gypo's algorithm, but may be, simillar improvements can be obtained by genetic algorithm optimization ... so I cannot say whose algorithm is faster ... two lewel counters or one level counters with binary observers.
... Oh ... the optimised two level counters got 3460 ... so even after small improvement of my algorithm it seems this two level counters would be for 100 prisoners better.

After several restarts, current status is:
3536.38 3536.38  3478.23  3478.23  2697   2697 9:0:12,4:0:7,4:1:7,4:1:7,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,2:1:5,2:1:5,2:1:5,2:1:5,2:1:5|1622,554,355|480,358,361,300|314|242
(now binary phases are encoded separately for upward run, top level and downward run)
It does not seem to be much improving so the probability of beating the 3460 record is very small.
Especially the average 3536 ...

some typos corrected[/edit]

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Apr 25th, 2007, 1:47pm
Um, could you explain in a little more detail how to turn that string of numbers into parameters for an algorithm so that I (or someone else) might be able to verify your results? ;)

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Apr 26th, 2007, 1:21am
Current state is ...
3530.47 3530.47  3501.72  3501.72 13609  13609 9:0:12,4:0:7,4:1:7,4:1:7,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,2:1:5,2:1:5,2:1:5,2:1:5,2:1:5|1622,554,355|480,362,361,289|299|242

SMQ: I will try:
The "genom" is divided into 5 parts by '|'
First part represents snowball prephases,
Second part represents lengths of counter phases,
Third part lengths of binary phases when binary levels increases,
Fourth part lengths of binary phases on top level,
Fifth part lenghts of binary phases when binary levels decreases.

Division into prephase part and the rest is needed,
the division of the rest into four parts is here only because the last number on the list is repeated and   it seems that these parts should behave a bit differently.

The prephase is divided into several snowballs (comma separates them in the "genom"), each snowwball into two parts. First number before colon is the number of days the snowball signalling takes (the first part), second number is the number of days the goal is reassigned, the third number is the goal the choosen counter should count to.

In the example above, there is 16 snowballs, first snowball takes 9 days, second 4 days, third 4+1 day, ....
After the snowball phases end, the counter phase starts of length 1622. After it binary phase 1 starts of length 480, after it binary phase 2 starts of length 362, after it binary phase 4 starts of length 361, after it top binary phase 8 of length 299, after it binary phase 4 of length 242, after it binary phase 2 of length 242, after it binary phase 1 of length 242, counter phase of length 554 follows, after it binary phase 1 of length 289, binary phase 2 of length 289, ....

Each prisoner starts with 1 token and 0 binaries.
During snowballs if he has token or binary, he lefts one token in the room (light on+number of tokens decrease). If he has no tokens or binaries he takes all tokens, subtracts the goal and sets binary to 1 (yes, counter have negative tokens during counting).
To prevent more binaries to be assigned to a prisoner, the goal reassignment parts are introduced ... after snowball ends, prisoner should take all tokens, subtract goal and increase its binary. But in the reassgnment part  (if binary was >1) he can decrease binary and left the corresponding number of tokens here. (I suppose the same was done in optimisation of two level counting).

During binary phases prisoners can operate with all binaries except one in all cases. The last one he can use only when tokens=0. This reduces the problem to counting that all 16 binary tokens are available.

Observers end method was described earlier ... each prisoner has a knowledge of binary "amount" that "enter" given binary level. When he register on/off on the level, he knows at least 2 binary tokens on this level were unioned into binary token on higher level.
So he updates the "amount" represented by binary tokens he knows that enter the higher level.
Of course if amount which entered given level is higher then knowledge of amount on lower level, the knowledge for lower level should be increased.
The "on" on given level 2^k means amount that entered this level is at least 2^k plus amount I know entered level 2^{k+1}.

When just one binary token is not available after counter phase, the probability a prisoner whould know this at the and of downward binary phase on level 1 is high.

One should be carefull during the binary phase ending to update the knowledge appropriately (even in the case tokens<0). ... this was the source of (serie of) bugs mentioned above.

I have reread the posts leading to 3460 days ... you used almost the same prephase ... except not using reassignment parts. Also you don't try to optimise the phase lengths. You use the lengths given by informed guess ... So may be, I will rerun the genetic algorithm for two stage process later to try to optimise the parameters.

One more thing ... I forgot to mention there is 2-3 day hook (from 5A2 forum) in the first snowball used.

some typos corrected[/edit]

Title: Re: 100 prisoners & a light bulb
Post by Rezyk on Apr 26th, 2007, 5:56pm
That explanation was a bit hard to follow for me; here is a guesswork-reinterpretation of it, along with pseudocode. (Can you see if it looks equivalent, Hippo?) I switch some terminology from:
• Instead of each badge being assigned a token collection goal, they come with an equivalent token deficit that is summed into the individual prisoner's token count, and can be passed around as negative tokens.

100 tokens are loaned out and distributed, one to each prisoner. To pay back the loan, each of the 16 snowball rounds generates one badge which comes with part of the deficit, and that must be paid off before the badge can be used to win. Counter phases try to pay off deficits by moving tokens to badge holders one at a time. The paid-off badges are gathered together in binary groupings; win when a prisoner can deduce that all 16 have been paid off.

main() {
Set each inventory to 1 token.
snowball(9, 0, 12)
snowball(4, 0, 7)
snowball(4, 1, 7)
snowball(4, 1, 7)
repeat 7 times: snowball(3, 1, 6)
repeat 5 times: snowball(2, 1, 5)
set i = 1
repeat indefinitely: {
//1622,554,355|480,362,361,289|299|242
next (i==1?1622 : i==2?544 : 355) days: If tokens>0, pass 1 token. //counter phase
next (i==1?480 : 289) days: If badges%2>=1 and tokens>=0, pass 1 badge.
next (i==1?362 : 289) days: If badges%4>=2 and tokens>=0, pass 2 badges.
next (i==1?361 : 289) days: If badges%8>=4 and tokens>=0, pass 4 badges.
set i = i+1
}
}

snowball(buildupLength, reassignLength, deficit) {
}

The simple win condition is collecting all 16 badges and having exactly zero tokens (no remaining deficit). One can also win by a deducing the number of active badges. For this, each prisoner independently tracks their answers to these:
• Have I witnessed an 8-group of active badges?
• Have I witnessed an 8-group of active badges, and then a free 4-group?
• Have I witnessed an 8-group of active badges, and then a free 4-group, and then a free 2-group?
• Have I witnessed an 8-group of active badges, and then a free 4-group, and then a free 2-group, and then a free 1-group?
Whenever a prisoner forms a new group of badges or pays off a deficit, a win can be declared if newGroupSize+witnessedGroupsSize=16.

• Title: Re: 100 prisoners & a light bulb
Post by Hippo on Apr 27th, 2007, 1:06am

on 04/26/07 at 17:56:22, Rezyk wrote:
 That explanation was a bit hard to follow for me; here is a guesswork-reinterpretation of it, along with pseudocode. (Can you see if it looks equivalent, Hippo?) I switch some terminology from: "binary" to "badge" Instead of each badge being assigned a token collection goal, they come with an equivalent token deficit that is summed into the individual prisoner's token count, and can be passed around as negative tokens.

Almost. Subtracting 7 tokens is equivalent to define goal 7. Negative tokens are passed only during 2nd part of snowballs (reassigning goals). Sorry ... yes in passing terminology you send negative tokens.

Quote:
 100 tokens are loaned out and distributed, one to each prisoner. To pay back the loan, each of the 16 snowball rounds generates one badge which comes with part of the deficit, and that must be paid off before the badge can be used to win. Counter phases try to pay off deficits by moving tokens to badge holders one at a time. The paid-off badges are gathered together in binary groupings; win when a prisoner can deduce that all 16 have been paid off.

There should be specified what happens when two badges are assigned to a prisoner ... only the last one waits for all being paid, others are available.

Quote:
 main() {  Set each inventory to 1 token.  snowball(9, 0, 12)  snowball(4, 0, 7)  snowball(4, 1, 7)  snowball(4, 1, 7)  repeat 7 times: snowball(3, 1, 6)  repeat 5 times: snowball(2, 1, 5)  set i = 1  repeat indefinitely: {    //1622,554,355|480,362,361,289|299|242    next (i==1?1622 : i==2?544 : 355) days: If tokens>0, pass 1 token. //counter phase    next (i==1?480 : 289) days: If badges%2>=1 and tokens>=0, pass 1 badge.    next (i==1?362 : 289) days: If badges%4>=2 and tokens>=0, pass 2 badges.    next (i==1?361 : 289) days: If badges%8>=4 and tokens>=0, pass 4 badges.    next 299 days: If badges%16>=8 and tokens>=0, pass 8 badges.    next 242 days: If badges%8>=4 and tokens>=0, pass 4 badges.    next 242 days: If badges%4>=2 and tokens>=0, pass 2 badges.    next 242 days: If badges%2>=1 and tokens>=0, pass 1 badge.    set i = i+1  }}

12-03-2008
Oops, I have chosed codding in which prephases are included in the first phase so 1622 should be replaced by
1622-9-4-2*5-7*4-5*3 in the code.[/edit]

Quote:
 snowball(buildupLength, reassignLength, deficit) {  subday 1: Create 1 badge and -deficit tokens. If badges>1 or (badges==1 and tokens>=-deficit+1), pass 1 badge and -deficit+1 tokens.  subday 2 through buildupLength: If badges>1 or (badges==1 and tokens>=-deficit+subday), pass 1 badge and -deficit+subday tokens.  next reassignLength days: If badges>1, pass 1 badge and -deficit+buildupLength tokens.}

Yes, it seems to be correctly translated to the "passing" terminology.
Edited 12-may-07: Except there is hook in the first snowball with high probability preventing collecting just one token (see 5 prisoners and a light bulb forum for details ... it saves less than 1 day anyway.)
Edited 26-nov-08: Behaviour of (badges==1 and tokens>=-deficit+subday) seems to be worse than (badges==1 and tokens=-deficit+subday). May be (badges==1 and (tokens>=-deficit+subday) and (tokens<-deficit+subday+2)) would be acceptable. ... snowball restarting paid by more tokens in hand of common prisoner seems to be too expensive.

Quote:
 The simple win condition is collecting all 16 badges and having exactly zero tokens (no remaining deficit).

Yes of course, but this condition neednot be tested separately, it is special case of the following win condition. The condition giving the algorithm robustness ... as all prisoners are very likely to be well informed ...

Quote:
 One can also win by a deducing the number of active badges. For this, each prisoner independently tracks their answers to these: Have I witnessed an 8-group of active badges? Have I witnessed an 8-group of active badges, and then a free 4-group? Have I witnessed an 8-group of active badges, and then a free 4-group, and then a free 2-group? Have I witnessed an 8-group of active badges, and then a free 4-group, and then a free 2-group, and then a free 1-group?Whenever a prisoner forms a new group of badges or pays off a deficit, a win can be declared if newGroupSize+witnessedGroupsSize=16.

Yes, typical example is seeing on,off,on,off during 4 badges phase.
First gives information ... there is a 4-group.
Second gives ... there is an 8-group
Third gives ... there is a 4-group and (I know also 8-group)
Fourth gives ... there is 2nd 8-group ... what is amount of 16 so we are done.

But if the same prisoner sees on,off,on during 4-badges phase and later on,off during 2-badges phase, he knows the amount in 4-groups and 8-groups was at least 12, now another 4-group is created so their amount is 16 and we are again done.

If a prisoner switches light ... he sees both states, but only if it is not forced nonintended switch during the phase end.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on May 9th, 2007, 1:57am
P.S.: Actual state of genetic algoritmh:
3526.80 3526.80  3511.31  3511.31 24390  24390 9:0:12,4:0:7,4:1:7,4:1:7,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,2:1:5,2:1:5,2:1:5,2:1:5,2:1:5|1622,554,355|480,362,361,289|299|242

The final state is:
3489.57 3489.57  3483.78  3483.78261756 261756
6:0:9,5:0:8,4:0:7,4:0:7,4:0:7,3:0:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,2:1:5,2:1:5,2:1:5,2:1:5|1668,554,362|495,367,361,289|313|269

The state for two counter phases started recently:
3518.17 3518.17  3472.10  3472.10  2038   2038 8:0:13,5:0:10,5:0:10,5:0:10,5:0:10,5:1:10,5:1:10,5:1:10,4:1:9,3:1:8|1988,1584,268
3515.24 3515.24  3488.22  3488.22  3332   3332 8:0:13,5:0:10,5:0:10,5:0:10,5:0:10,5:1:10,5:1:10,5:1:10,4:1:9,3:1:8|1988,1584,268
3502.26 3502.26  3473.11  3473.11  9134   9134 8:0:13,5:0:10,5:0:10,5:0:10,5:0:10,5:1:10,5:1:10,5:1:10,4:1:9,3:1:8|1997,1652,343

I have let the algorithm to "restart" after 10^6 simulations. The state before restart follows:
3487.97 3487.97  3467.95  3467.95 79493  79493 8:0:13,6:0:11,5:0:10,5:0:10,5:0:10,5:0:10,5:1:10,4:1:9,4:1:9,3:1:8|1929,1582,387
Current status is:
3485.89 3485.89  3470.42  3470.42 22565  22565 7:0:12,5:0:10,5:0:10,5:0:10,5:0:10,5:1:10,5:1:10,5:1:10,4:1:9,4:1:9|1965,1646,336
[26.11.08 text above moved from the previous post]

The final state of binary-observers is:
3489.57 3489.57  3483.78  3483.78261756 261756
6:0:9,5:0:8,4:0:7,4:0:7,4:0:7,3:0:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,3:1:6,2:1:5,2:1:5,2:1:5,2:1:5 |1668,554,362|495,367,361,289|313|269

The final state of two stage counters is:
3485.19 3485.19  3467.06  3467.06 310426 310426 9:0:14,6:0:11,6:0:11,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,3:1:8 |1973,1663,404

BTW: You can see the unstability of the algorithm as small mutations change average to 3485 while these parameters give 3467.

Second most common gen was
8:0:13,7:0:12,6:0:11,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,4:1:9,4:1:9|1973,1663,404
with average 3473.35  form 116695 experiments.

May be, my initialisation is worse than yours, but so far it does not seem to approach 3460 days. The simulation shows that for 100 prisoners two stages couning is better than binary-observers method.
(At least the local minimum of observers method is above the minimum of two stages method).

The simulation results are based on pseudorandom generator this is the main source of inaccuracy.

I can change mutation in the way the goals in optimal case are not equal but have g,g,g,g,..,g,g+1,g+1,g+1,...,g+1 shape but I guess improvement in such a case cannot exceed 8 days ... I expect 1 or 2 days improvement.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on May 9th, 2007, 2:20pm
On the trail of the elusive marker-token:

Since first reading through this thread years ago I've been searching for a way to combine the strong start of a token-based strategy (leader, badges&crowns, etc.) with the strong finish of a marker-based (distribution) strategy.  Well, here's a possibility.  It clearly loses to any of the token strategies -- even single-leader -- but I believe once tuned it will beat any of the existing distribution strategies, and at least it's somewhat novel.

Maybe it will spark some fresh ideas.  Or maybe it's just crap. :)

Basically it's a way to hand out the numbers 1-100 for a distribution scheme reasonably efficiently, but there's a large penalty for failure of that portion of the scheme.  I hope to have simulation results available in the next couple days.

Stage 1: Assignment.

This stage is divided into 100 rounds numbered 1 through 100 of varying lengths, from a few days to a few hundred days as roughly C*100/(101 - n) for round n with C fairly small.  In each round, the first prisoner to enter who has not yet been assigned a number assigns himself number n and turns on the light.  Any other prisoner who sees the light on remembers that prisoner n has visited (distribution scheme).  If any number goes unassigned (the light is still off at the end of the round), either the last prisoner of that round or the first prisoner of the next round must remember that the number is unassigned -- it will be his responsibility to try to get it reassigned in a later stage.

Stage 2: Distribution

Just like any other distribution scheme: divide into 100 equal-length rounds (rmsgrey's work suggests 30-70 days per round may be roughly optimal), if prisoner n enters during round n he turns on the light; anyone observing the light on notes that prisoner n has entered; if anyone observes all 100 have entered he declares victory.

Stage 3: Reassignment

Here's where the major penalty comes in if stage 1 failed.  Divide into 100 equal-length rounds of, maybe, 150-ish days each.  In each round, if a prisoner enters who knows that n is still unassigned, he turns on the light.  After that, if any prisoner enters who was not yet assigned a number he assigns himself number n and turns off the light.  If the last prisoner of the round (or the first of the next) finds the light on, he remembers that n is still unassigned.

Repeat stages 2 & 3 as necessary.

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Hippo on May 9th, 2007, 3:08pm
SMQ: You can almost translate this into token terminology in the following way:

There are tokens of 100 different kinds.
Assignment ... assigns token to a prisoner without a token so far and after that distribution subphase starts ... there is signal left for other prisoners improving their knowledge about token assignment. If the assignment failed a prisoner gets second token.

Distribution subphase ... does nothing unless the only prisoner with current kind of token enters. After that knowledge may be distributed.

Reassignment subphase ... does nothing unless the only prisoner with current kind of token enters after that does nothing unless a prisoner without a token enters. After that knowledge may be distributed.

This will be ineffective as it requires a lot of phase switching, You cannot know which phases are not required. The Distribution and Reassignment phase lengths should be longer than 100 days (probably 200 days) as they do nothing if the prisoner with the token does not enter. If a reassignment fails you must wait at least whole cycle of reassignments ... One cycle takes at least 20000 days .... (oh sorry ... tokens with small numbers are assigned well with higher probability, but it is surely more than 5000 days)

Oh sorry once again ... the method neednot be so bad ... the distribution phases does not wait for the only prisoner with the corresponding token but to anybody who knows the token was assigned. The problems are only with error recovery ... with the redistribution phases.

The Assignment phases should be long enough to have the fail probability to say 1/1000 (advantage is that assignment phases serve as distribution phases as well). ... in such a case fail of all assignment phases will be with probability around 1/10 what may be OK.

But if I understand it well, the process cannot end unless a prisoner enters the room 99times.
I have tried to approximate the probability a prisoner enters the room 99times before day 5000.
... it gave me something like 20000/2100 ... so don't expect to make a new record. Sorry once again ... this is not good approximation!!
Better approximation is 20000e50/2100=eln 20000+50-100ln 2 approx e-9.41.

Back to the search for optimal parameters of two level counting or counting with binary observers:
I have made the change to allow small increase of "optimal goals" in mutations. Furthermore, I have changed meaning of the first phase length ... it starts now on day 0 so prephases are part of its time. I hope this would improve the genetic algorithm stability. ... so wait another two weeks for results ;)

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 10th, 2007, 7:59am
A trivial optimisation for SMQ's latest proposal: everyone knows that the prisoner who enters on day 1 will have token 1 and have been into the room, which means that you don't need to consider him in any future signalling. It may be worth throwing a snowball in early as well - rather than passing out copies of token 2, instead aim to pass out copies of tokens 2,3 and 4 simultaneously. You probably want to be reasonably conservative with such snowballs - using them saves maybe 50 days per additional number, but costs a lot when they miss.

In any case, you want the initial assignment sub-phases (apart from day 1) to all be long enough to get a reasonable number of copies of the phase token out there - otherwise you lose the major advantage of dynamic label assignment - not having to wait for a specified prisoner to visit to start copying a given labelled token.

There's a fairly obvious improvement to the reassignment phase too: rather than trying to pass labels to unlabelled prisoners, pass unlabelled tokens to prisoners with spare labels.

Rather than multiple numbered subphases, in which things will only happen if that label hasn't yet been assigned, have a single reassignment phase in which prisoners with unlabelled tokens pass their token at the first opportunity, and prisoners with an unassigned label collect any token that comes there way and label it. That way, the entire phase is potentially useful as long as there's any unassigned labels rather than 90%+ of it being wasted time.

Terminology:

Each prisoner starts with an unlabelled token.

During the assignment phase, 100 labels are created and handed out - where possible, to prisoners with an unlabelled token. Any time a prisoner has an unlabelled token and one or more labels, he labels the token with the lowest rank label.

Labelled tokens are automatically copied by anyone who sees them, and copies are passed around during the appropriate subphases of the assignment and distribution phases.

As soon as a prisoner sees 100 different tokens, he can claim victory.

It's also possible to generate a victory during a reassignment phase if someone sees enough unlabelled tokens pass by, or during a distribution phase if someone with an unlabelled token collects 99 labelled tokens...

Title: Re: 100 prisoners & a light bulb
Post by Hippo on May 10th, 2007, 1:24pm
SMQ, rmsgrey: Snowballs reduces the number of required visits of the prisoner declaring victory from 99 to say 90 ... depends on the snowball total lengths.
The probability a prisoner enters the room 90 times during first 5000 days remains negligible so this cannot beat the best algorithms. (You even cannot expect all the visits are usefull ...)

I don't understand the anonymous reassignment ... in this method you need to know the token "name" to be able to distribute the information later. With anonymous token you cannot do that.

Wait! ... Oh yes, there is a possibility ... when accepting anonymous token you create "new name" for it. So there will be more than 100 kinds of distribution phases (some of them having nothing to distribute).

Back to the finding optimal parameters:
I have checked mutation strategy and find some problems. ... The results after their correction seemed to be interesting ;) ...

One more thing: I plan to run genetic algorithm also for variant with 8 counters ... therefore saving one binary level. This will prolong first phase around 650 days what would be compansated later I hope.

It seems all three methods are roughly equal.
3500.79 3500.79  3468.37  3468.37 283705 283705 9:0:14,6:0:11,5:0:10,5:1:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,4:1:9| 2015,1744,481
3526.40 3526.40  3471.83  3471.83 19345  19345 6:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,3:0:5,3:1:5,3:1:5|1749,554,362|493,367,361,289|313|269
3493.37 3493.13  3472.99  3472.99  1231   1231 12:0:17,10:0:15,8:0:13,7:1:12,6:1:11,6:1:11,6:1:11,5:1:10|2263,554,411 |349,361,289,280|268|269

I would change parametrisation for 16binary adding one parameter to upward runs. The average of all runs is best for 8binary. 8binary is far for achieving its minimum ... even the upward binary string is nondecreasing.

Hmm, it seems to me that genetic algorithm could work for weeks and not to approach optimal values  . As the quality of results is bounded by quality of pseudorandom generator I stop this experiment.

So far the two level counting scheme is the best one with average around 3470, observers method with either 8 or 16 counetrs have average around 3490.

Title: Re: 100 prisoners & a light bulb
Post by AL007 on May 30th, 2007, 9:08am
I have spent a good part of the last few days reading these 20+ pages and have found the evolution of the optimal solution fascinating!  I complement all of the bright and creative people involved.

If anyone is still interested, there is a legitimate way to at least double the bandwidth and significantly shorten the problem.  About two years ago Grimbal stated: " It doesn't matter how long a bulb can last.  It will get replaced.  Or not.  The important thing is whether the switch is up or down."

Therefore, we have at least four states:  switch up with bulb on, switch up with bulb off (unscrewed), switch down but will turn on, and switch down and won't turn on (unscrewed).  Additionally, most switches will stay at the midpoint, so we may have five states.

Of course, if we allow this we could measure how far the bulb was unscrewed and add even more bandwidth.   File this with the other cheats. . . .

Title: Re: 100 prisoners & a light bulb
Post by Hippo on May 30th, 2007, 12:59pm
Hmm ... you have read 20+ pages so you know, this "solution" is not what are we interested on.

I agree with the observation the bulb is not important - the switch is important, but in this riddle we are talking about one bit of information "problem".

If you are interested in switches with more states ... there is another thread.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 31st, 2007, 5:44pm
And I'm pretty sure both the intermediate switch state and the partially loosened bulb have been suggested in the past (in fact, I think I may have been the one to suggest the 3-state switch)

Title: Re: 100 prisoners & a light bulb
Post by srn347 on Aug 29th, 2007, 11:59am
The first one turns it on(unless it's already on)and draws a tally mark on the wall). Everyone who enters sees the tally mark(s) and adds one. When a person sees 100 after drawing theirs, they say they were the 100th person. If counting 100 in groups of 5 is to much for them, they group the groups of 5 into groups of 5 groups by circling every 5 groups in one circle.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Aug 29th, 2007, 3:12pm

on 08/29/07 at 11:59:56, srn347 wrote:
 The first one turns it on(unless it's already on)and draws a tally mark on the wall). Everyone who enters sees the tally mark(s) and adds one. When a person sees 100 after drawing theirs, they say they were the 100th person. If counting 100 in groups of 5 is to much for them, they group the groups of 5 into groups of 5 groups by circling every 5 groups in one circle.

You must be a genius, 23 pages and noone found such solution ... please read it first, don't spam it

Title: Re: 100 prisoners & a light bulb
Post by srn347 on Aug 29th, 2007, 4:48pm
Read 23 long pages?! I will if you try the 3 nearly impossible riddles post.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Aug 30th, 2007, 2:10am

on 08/29/07 at 16:48:07, srn347 wrote:
 Read 23 long pages?! I will if you try the 3 nearly impossible riddles post.

Just reading the first page would have done. Reply #13 includes an energy saving tip that your version overlooks

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Sep 11th, 2007, 10:08pm
um could someone help me out?  im not as smart as most of you, and im trying to figure out how the solution given by Gypo works.  Im confused on stage 0.  i assume the bulb is off initially? but doesn't turn off at the end of each cycle correct?
Im just confused on the wording.

For cycle 0,
Quote:
 If he now has one or more tokens or one or more badge, he turns the light on and subtracts one token from his inventory, even if he ends up with a negative number of tokens. If the prisoner has no tokens and no badges, he switches the light off and gets a badge.
do i do this no matter the if the bulbs on or off?

After this step what is suppose to happen? theres suppose to be 10 people with badges right? and 1 witha crown?  what about tokens im confused about this.  how are you suppose to count people going through the first 40 days and how do those people know if they are counted or not?  Sry if this doesn't make much sense just ask me and ill try to clarify.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Sep 12th, 2007, 6:08am
Sounds like you're close, Wardub; it took me a while to grasp what was going on in that stage too.

The first round of stage 0 is a little special:

- Everyone starts out with one token and nothing else.
- On day one (only), the prisoner who enters turns the light on (if it isn't already), and mentally "drops" his token.
- On day two (only), if the same prisoner enters again, he mentally "picks up" his token, "gets" a badge and a crown, and turns the light off (to signal that the first badge has been assigned).  Otherwise, if a different prisoner enters, he mentally "drops" his token and leaves the light on.
- On days 3 and 4, if the light is already off (signaling that the first badge has been assigned already), the prisoner who enters does nothing.  If the light is on and the prisoner has a token, he mentally "drops" it and leaves the light on; otherwise he "picks up" a number of tokens equal to the number of days that have passed, "gets" a badge and a crown, and turns the light off.

Then there are nine rounds that are all the same:

- On day 5, 9, 13, etc. If the light is on when a prisoner enters (indicating that no badge was assigned in the previous round) he picks up four tokens, gets a badge (and a crown iff it is day 5), and turns the light off.  Now the procedure you quoted above happens (with the light always off to begin): If he has any tokens or any badges, he drops a token (even if that means he now has -1 tokens) and turns the light on; otherwise he leaves the light off and gets a badge.
- On all other days, things proceed as in days three and four: nothing happens if the light is off, otherwise the prisoner drops a token if he has one, or takes the accumulated tokens for the round and gets a badge (but not a crown) if not.

Finally, before other instructions, at the start of day 41, if the light is on, the prisoner picks up four tokens, gets a badge, and turns the light off.

At this point, ten badges and a crown have been assigned, and the total of all prisoners mental token counts is 100 (every token that was "dropped" was later "picked up"), even in the extremely unlucky case that one (or worse, more) of the prisoners with a badge has a negative count.  With a bit of luck, no prisoner has more than one badge, and the prisoners with badges all have more than one token counted already.

From here, things go much simpler.  Stage 1 (remember that we start with the light off possibly after a prisoner picked up the final basge first thing on day 41):
- If a prisoner has a token but no badge, and the light is off, he drops his token and turns the light on.
- If a prisoner has a badge and less than 10 tokens (or two badges and less than 20 tokens, etc.), and the light is on, he picks up the token and turns the light off.
- In all other situations, nothing happens.

At the start of the first day after stage 1, if the light is on, the prisoner turns it off and picks up a token, whether or not he has a badge. (Don't want to lose that token!)  This way tokens are "passed" to the prisoners with badges, up to 10 tokens per badge.

Then, stage 2, like stage 1 but a "level up" (again starting with the light off from the last act of stage 1):
- If a prisoner has one or more badges and at least 10 tokens, and the light is off, he drops one badge, subtracts 10 tokens, and turns the light on.
- If a prisoner has the crown, and the light is on, he picks up the badge (and 10 tokens) and turns the light off.  If he now has 10 badges (or, equivalently 100 tokens) he declares victory.
- In all other situations, nothing happens.

This way "filled" badges are passed to the single prisoner with the crown; once he has them all, he knows all 100 tokens are accounted for, and he declares victory.  If at the end of Stage 2 there is no victory, every keeps what they have and repeast stage 1, then stage 2, etc. until victory is finally declared.

Hope that makes things clearer!

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Sep 12th, 2007, 10:26am
thanks, i don't have time to read it all now, i have class, but i think i will be able to understand.

Also i found 2 special cases, i read the whole thread a while ago and i no you guys caught the case where the light is still on, on the last day  of the cycle.  but i found another "special case" but im pretty sure you have found it also, because you're all so smart. anyways

when i made my program, im very new to it so i used lots of whiles and ifs and stuff.  anyway i only made the win scenario if the second cycle.  but i found out there is a slight possibility that you can declare a win in the first cycle, its easy to see if you actually were doing this riddle, but pretty easy to overlook while programming.

if after the first time through the first 2300 day cycle, all the assistant counters have filled their badges but the Lead counter or w/e hasn't filled his.  then if he counts all 9 assistant counters, then he knows that when he completes his badge then every prisoner has been through.  so in my program if 100 days in to the second time through the first cycle, the lead counter fills his badge he can declare a win, but in my program the program would wait till cycle 2 and then declare a win adding on like 1000 days.  Im sure you guys have already found this out, but w/e it probaby doesn't shave off even .1days after 1,000,000 times because its chances of happening are rare

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Sep 15th, 2007, 7:50pm
ok i finally understand stage 0, but i have questions, it says that it will get rid of the problem with prisoners having multiple badges, but it looks like prisoners can still get multiple badges if their the first person in on  the start of the cycle and the light is on , and they have atleast one badge.  also does anyone have code for stage 0? could someone post it?

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Sep 16th, 2007, 12:25pm
See the top third of the 23page ... the Rezyk one
... the snowball phases do not differ ...

in the pass (something) terminology you either switch light off or you let it on and subtract corresponding (something) from your inventory and virtualy let it in the room.

The amount is uniquely defined by the night number!

Who enters with the light on starts with grabbing (something).

----
And yes, you cannot prevent to have more badges in the same hand. You only can minimize the probability of it happen. ... There is nonzero but very very small probability all the first 10000 days the same prisoner enters ...

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Sep 17th, 2007, 6:12am

on 09/15/07 at 19:50:06, Wardub wrote:
 also does anyone have code for stage 0? could someone post it?

To get exactly gypo's algorithm, set all badgesizes to 10 (except the first 0) and all rounddays to 4 (except for the first 0) at the top.  Also be aware that the code as posted overcounts by one day.  You can change int totaldays = 1 to int totaldays = 0 at the start of the second section to fix it.

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by mzbach22 on Jan 2nd, 2008, 10:13pm
I haven't read the entire forum; so, please excuse me if I am re-suggesting an idea.

The first prisoner / (day one) breaks the light bulb into 100 pieces. (The prisoner will know he/she is the first because the light bulb will still be whole). Then that prisoner takes one shard of the light bulb and leaves the rest in the room. As long as the prisoners only take one shard each (and they are very careful not to break the shards when entering the room) then the prisoner who enters the room and finds no shards declares that all the prisoners have been in the room.

The only potential problem may be that there is no light for the prisoners to see the shards. In that case, the first prisoner who shatters the light bulb arranges it into a 50 x 50 square and the prisoners all take one pieces from the lower right corner and snake their way up.

Another solution. Take the filament out of the light bulb and straighten it. The first prisoner makes a small bend in the filament. The second makes another small bend. Finally one hundred bends will be made and the last prisoner (albeit they have to count a lot of tiny bends) will be able to declare that everyone has been there.

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Jan 3rd, 2008, 4:39am
Various out-of-the-box solutions have been proposed, shards of glass, scratching marks on the wall, unscrewing the light bulb in small increments, defecating, bribing the guards, etc.

Title: Re: 100 prisoners & a light bulb
Post by tiber13 on Jan 4th, 2008, 5:56am
i think most people are forgetting that the problem is about, 100 pecies of info, and 1 two state transmittor, the 100 have to know that the other 99 of them have been to this "Place"

it is only worded that way to make it more realistic.

Just given you a reality check

Title: Re: 100 prisoners & a light bulb
Post by Ghost Sniper on Jan 4th, 2008, 6:33am
I believe that the problem with this riddle is that it can be interpreted in too many different ways. For example, can the walls be marked or not? Can you use anything from the room as a marker? and so on, and so on. The only way we will be able to get a completely correct answer is if the riddle is VERY specific on what is allowed and what is not.

Title: Re: 100 prisoners & a light bulb
Post by Paul Hammond on Jan 4th, 2008, 11:34am
It's easy enough to restate the puzzle so that you avoid all the "leave something in the room" answers. Something like:

100 prisoners are imprisoned in separate windowless, soundproof, smellproof etc. cells. Once a day the warden randomly chooses one of the prisoners and visits his cell. The prisoner is allowed to say to the warden either "on" or "off", after the warden has told him which of the two words yesterday's prisoner said.

The prisoners are allowed to meet up before to discuss their strategy...
etc. etc.

They never have to visit some room with a lightbulb in it.

Title: Re: 100 prisoners & a light bulb
Post by Tedp20 on Jan 4th, 2008, 1:54pm
If you think too hard about the problem, it seems that it just gives you a headache. Think in simple terms guys.

---

100 prisoners are imprisoned in solitary cells. Each cell is windowless and soundproof. There's a central living room with one light bulb; the bulb is initially off. No prisoner can see the light bulb from his or her own cell. Each day, the warden picks a prisoner equally at random, and that prisoner visits the central living room; at the end of the day the prisoner is returned to his cell. While in the living room, the prisoner can toggle the bulb if he or she wishes. Also, the prisoner has the option of asserting the claim that all 100 prisoners have been to the living room. If this assertion is false (that is, some prisoners still haven't been to the living room), all 100 prisoners will be shot for their stupidity. However, if it is indeed true, all prisoners are set free and inducted into MENSA, since the world can always use more smart people. Thus, the assertion should only be made if the prisoner is 100% certain of its validity.

Before this whole procedure begins, the prisoners are allowed to get together in the courtyard to discuss a plan. What is the optimal plan they can agree on, so that eventually, someone will make a correct assertion?

--

If during the preliminary meeting, the prisoners agree to only toggle the switch at a specific time during the day, they can safely assume that there is a prisoner in the courtyard. The prisoners cannot see the courtyard, and they cannot see the light bulb, but that doesnt mean they cannot see the light emitted from the light bulb. So therefore, if each prisoner agrees to only toggle the switch connected to the light bulb as long as they have not previously been allowed into the courtyard, they can safely say that on the 100th toggle, each prisoner has been in the courtyard at least once.

:P

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Jan 5th, 2008, 2:58pm

on 01/04/08 at 13:54:20, Tedp20 wrote:
 If you think too hard about the problem, it seems that it just gives you a headache. Think in simple terms guys.---100 prisoners are imprisoned in solitary cells. Each cell is windowless and soundproof. There's a central living room with one light bulb; the bulb is initially off. No prisoner can see the light bulb from his or her own cell. Each day, the warden picks a prisoner equally at random, and that prisoner visits the central living room; at the end of the day the prisoner is returned to his cell. While in the living room, the prisoner can toggle the bulb if he or she wishes. Also, the prisoner has the option of asserting the claim that all 100 prisoners have been to the living room. If this assertion is false (that is, some prisoners still haven't been to the living room), all 100 prisoners will be shot for their stupidity. However, if it is indeed true, all prisoners are set free and inducted into MENSA, since the world can always use more smart people. Thus, the assertion should only be made if the prisoner is 100% certain of its validity.Before this whole procedure begins, the prisoners are allowed to get together in the courtyard to discuss a plan. What is the optimal plan they can agree on, so that eventually, someone will make a correct assertion? --If during the preliminary meeting, the prisoners agree to only toggle the switch at a specific time during the day, they can safely assume that there is a prisoner in the courtyard. The prisoners cannot see the courtyard, and they cannot see the light bulb, but that doesnt mean they cannot see the light emitted from the light bulb. So therefore, if each prisoner agrees to only toggle the switch connected to the light bulb as long as they have not previously been allowed into the courtyard, they can safely say that on the 100th toggle, each prisoner has been in the courtyard at least once. :P

For starters, the bulb's not in the courtyard - they meet in the courtyard to avoid them all visiting the living room before they start...

Secondly, seeing the light from their "windowless and soundproof" cells is gonna be tricky...

Title: Re: 100 prisoners & a light bulb
Post by Iceman on Jan 11th, 2008, 8:20am

Quote:
 Also, the prisoner has the option of asserting the claim that all 100 prisoners have been to the living room.

If this isn't a new prison, rather an old one, although reconstructed to a higher standard, then at the very beginning of the whole procedure, 1st prisoner can make the assertion. Of course, I'm talking about previous 100 prisoners, which all had access to the central living room. ::)

Title: Re: 100 prisoners & a light bulb
Post by Iceman on Jan 12th, 2008, 11:37am
One thing isn't quite clear to me. Should it be? The riddle states that there is one bulb in the central living room. But what does that mean, exactly? Does it mean that when the coiled-coil filament burns out, then it will be replaced with a new bulb? Or when it burns out, it will not be replaced at all? If the latter is the case, then perhaps considering the approximate duration of the bulb might be beneficial to prisoners. It probably won't help prisoners though, but it might clear up things a bit for riddlers.  ;)

Title: Re: 100 prisoners & a light bulb
Post by Icarus on Jan 12th, 2008, 12:53pm
It's an LED bulb, with theoretically unlimited lifetime. And the switch and wiring are also of exceptionally rugged design.

Indeed, our inmates would have been free from mechanical concerns had there not been a power outage on one day when the bulb was supposed to be on.  ::)

Title: Re: 100 prisoners & a light bulb
Post by Grimbal on Jan 12th, 2008, 3:06pm
When the lamp burns out, the position of the switch is enough to carry the information.

I am assuming a classical 2-position switch.

Title: Re: 100 prisoners & a light bulb
Post by Iceman on Jan 16th, 2008, 1:43pm
Will someone finally solve this prison riddle in the name of Christ and Virgin Mary!  :P

Title: Re: 100 prisoners & a light bulb
Post by Ghost Sniper on Jan 16th, 2008, 2:19pm
The only problem, Icey, is that not even Wu knows the intended answer. So even if he shows up, he is not going to be able to help us, and that includes clues.  :(

FOR GOODNESS SAKE, WE HAVE TO FIND WHO WROTE THIS RIDDLE!

edit:

Yoiks, I just found this:

http://www.ocf.berkeley.edu/~wwu/papers/100prisonersLightBulb.pdf

edit 2:

So many people refer back to the riddles site when talking about this riddle. It almost makes it seem as if Wu wrote the riddle.

Title: Re: 100 prisoners & a light bulb
Post by Paul Hammond on Jan 17th, 2008, 6:22am
I think William Wu has actually said, possibly in this very thread, that his intended solution was the "single leader" solution with preliminary "snowball" round.

I think what happened is that this puzzle arose out of a possibly unintentional but crucial variation on the original IBM "23 prisoners" puzzle. In that puzzle, the warden visits at arbitrary intervals, not once per day, so any solution that makes use of the day number won't work. It is difficult to see how you could have multiple counters, snowball phases, or anything other than "token passing" in those circumstances, so for that puzzle Single Leader may be optimal.

Having the warden visit once per day doesn't sound like it would make much difference but, as we have discovered, it does.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Jan 17th, 2008, 6:50am

on 01/17/08 at 06:22:44, Paul Hammond wrote:
 so for that puzzle Single Leader may be optimal.

Although I can't find the paper at the moment, I believe the single leader solution to the IBM version (http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/challenges/July2002.html) has indeed been proven optimal.

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Iceman on Jan 17th, 2008, 8:15am

on 01/17/08 at 06:50:18, SMQ wrote:
 Although I can't find the paper at the moment, I believe the single leader solution to the IBM version (http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/challenges/July2002.html) has indeed been proven optimal.

I second that, even though I'm not that good at these kinds of riddles. The single leader solution makes perfect sense to me.

Title: Re: 100 prisoners & a light bulb
Post by Paul Hammond on Jan 17th, 2008, 9:26am

on 01/17/08 at 06:50:18, SMQ wrote:
 Although I can't find the paper at the moment, I believe the single leader solution to the IBM version (http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/challenges/July2002.html) has indeed been proven optimal.--SMQ

You could imagine a scenario in which the prisoners simply guess the rate at which the warden will visit the cell, and use some kind of staged scheme based on that. If the warden does in fact visit at roughly that rate, their scheme could work out faster than Single Leader would have done.

Of course, we have to assume that the warden could visit at a rate of a billion times a second, or only once per trillion millennia, with equal probability, so the probability that their guess will be usefully close to being correct approaches zero  :). Whereas the single leader scheme doesn't care how often he visits.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on Jan 17th, 2008, 12:24pm

on 01/17/08 at 09:26:43, Paul Hammond wrote:
 You could imagine a scenario in which the prisoners simply guess the rate at which the warden will visit the cell, and use some kind of staged scheme based on that. If the warden does in fact visit at roughly that rate, their scheme could work out faster than Single Leader would have done.Of course, we have to assume that the warden could visit at a rate of a billion times a second, or only once per trillion millennia, with equal probability, so the probability that their guess will be usefully close to being correct approaches zero  :). Whereas the single leader scheme doesn't care how often he visits.

The problem with any staged system with unknown intervals between visits is how you handle transitions between stages - neither of the two prisoners on either side of a stage boundary can know they are on either side of the boundary, and it's also possible for one or more stages to pass without anyone visiting - so even if you find a scheme that compensated for one stage transition, it could still fall apart when carried out across multiple stages...

Title: Re: 100 prisoners & a light bulb
Post by Iceman on Mar 20th, 2008, 3:53pm
The 1st prisoner unscrews the bulb and puts it in particular corner, as previously agreed amongst the prisoners in the courtyard. And every time a prisoner is 1st time in the above room, he simply moves it a bit clockwise along the walls. In fact, the bulb will act like mechanical hand does, pretty much.

This might yield enough information to make the proper assertion.   :-/  ;)

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Mar 21st, 2008, 1:02am
The topic is not dead, actually I was thinking about it in the small amount of free time I had last two days. But please don't spam it with out of box posts.
What I am thinking about is a combination of observers stop and Rezyk phase switch cost reduction method.
The cost will be that there will be dedicated prisoner not sending his token in binary phases and each upward superphase will end in one level lower than previous (the tokens of nondedicated prisoner will be split in the top phase and observers should ignore the information above this level). Downward superphases after the first one can be discarded at all.
After several superphases this will end at two level scheme.

Actually this changes the main streem of the algorithm only very little, but the cost of phase switches during error recovery is reduced.

Whether it leads to higher average time or smaller will be left to experiment. I expect only small difference which may be hard to notice.

Title: Re: 100 prisoners & a light bulb
Post by Master of Everything 42 on Mar 22nd, 2008, 8:21am
wouldnt a light bulb burn out in ~27 years?

Title: Re: 100 prisoners & a light bulb
Post by towr on Mar 22nd, 2008, 8:39am

on 03/22/08 at 08:21:13, Master of Everything 42 wrote:
 wouldnt a light bulb burn out in ~27 years?
I think there is still a lightbulb made by edison himself burning somewhere. The life expectancy is much lower though; but there's exceptions. And the lightbulb is irrelevant here anyway, as long as the switch has distinguishable states.

Title: Re: 100 prisoners & a light bulb
Post by Iceman on Mar 22nd, 2008, 9:35am

on 03/22/08 at 08:21:13, Master of Everything 42 wrote:
 wouldnt a light bulb burn out in ~27 years?

Prisoners will burn out in 27 years.

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 22nd, 2008, 6:39pm

on 03/22/08 at 08:39:26, towr wrote:
 I think there is still a lightbulb made by edison himself burning somewhere.

Yep, been burning for over 100 years (http://www.centennialbulb.org/photos.htm) at a fire station in Livermore, California.

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Mar 23rd, 2008, 6:02am
I have just run an experiment which should compare the algorithm with counnters on level 0 and observers on binary levels above it, where in 1st case the levels on binary phases are in /\///////... shape and in the other in /\/\/\/\... shape.

So I compare only cases when /\/  didn't terminate yet. And the /\//// shape for this sample is about 130 days faster
(currently 6647/6785).

This sample is around 1/40 of all cases so this improves the average by more than 3 days.

... I will probably implement the binary phases reduction mentioned recently ...
I cannot realy estimate whether this beats the 2 phases counters or not.

Hmm I became a bit sceptic. ... the combination of observers and crown ... if some binary counter fails and crown gathers half the badges the observers take almost no info so not to send the badge as a crown disqualify observers. On the other side if crown sends the badge the counter phase takes longer as the crown starts from zero. I will probably let the crown act as other badge owners during the initial top binary phase. After that the crown will start acting usually from zero. Choice of crown can be done as the prisoner taking tokens in the first snowball. Making rather big goal at the first snowball actually prevents the crown from loosing his badges at the top binary phase. We can choose in other way, but this seems to preserve maximal probability it gathers some badges. In the binary phases under top crown can deny sending his badge and he can gather badge to round his badges on this level to even number. ... this is rather frustrating you intend to gather almost all badges outside the crown hands during initial binary up and down to be observers well informed, but in the following up phases you do everything to collect all badges in the crown hands. Each decission has unpredictable consequences. One strategy for crown may be to collect badges (to even them) only in last say 150 days of each binary upward phase.
And collect all during downward phases. This highly increases probability that another prisoner lights the bulb on the topmost binary phase ... so observers will be well informed and the crown neednot loose his badges on the top level....

Ohh ... new fresh idea:
For the first top binary phase crown can act as all other badge owners until say last 150 days of the phase when it switches strategy to crown ... collecting badges at all costs. Observers didn't stop the top binary phase when they see on/off swith ... there is no reason for that as if this unions last two binary tokens the badge holder declares victory himself.
Observers only get info "At least half binary tokens entered the top level." whenever they see switch on during the phase.

This makes all observers well informed. And probability the crown gets more than half of all badges during the binary up phases is very high (with his passivity until last say 150 days during upward binary phases). ... I became a bit more optimistic ;)

So the experiment was run ... first parametrisation gives result worse by 200 days  it was actually around 500 days[/edit]:( this is probably caused by wrong spread of info during downward binary phases. I would probably change the strategy once more ... crown will act as a binary on the initial up phases and in the first part of top phase as well as in the first part of downward phases. Observers shouldnot gather info in the second part of the downward phases.

The last improvement gives around 3740 for current parametrisation so observers without crown are better so far.
But the mutation of parameters is a slow process so we may be surprised later (only if the original choise was very very bad).

Title: Re: 100 prisoners & a light bulb
Post by Master of Everything 42 on Mar 24th, 2008, 6:26am
It's 4-watt too.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Mar 24th, 2008, 7:20am
It seems the counters on level 0 and observers on levels /\////// seemed to be the most perspective.

Current state and most common gen:
3498.78 3497.31  3456.88  3456.88   857    857 7:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,5:0:6,5:0:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5|1702,581,379|465,377,371,298|325,317|278
3496.03 3495.62  3463.18  3463.18  2574   2574 6260.80    0.00 7:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,5:0:6,5:0:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5|1702,581,379|465,377,371,298|325,317|278

The combination with "Rezyk":
3743.90 3742.53  3536.31  3536.31   291    291 7:0:9,6:0:8,6:0:8,5:0:7,4:0:6,4:0:6,5:0:6,5:0:6,5:0:6,5:0:6,5:0:6,5:0:6,5:1:6,4:1:5,4:1:5,3:1:4|1861,632,419|522,417,411,330|362:172,551|311:172
3730.32 3729.80  3688.08  3688.08   465    465    0.00 6668.00 7:0:9,6:0:8,6:0:8,5:0:7,4:0:6,4:0:6,5:0:6,5:0:6,5:0:6,5:0:6,5:0:6,5:0:6,5:1:6,4:1:5,4:1:5,3:1:4|1861,632,419|522,417,411,330|362:172,551|311:172

here x:y in  binary phase lengths denotes x ... len of the phase, y ... number of days to end of phase being crown subphases

Other notation ... see page 23.

I have to stop the simulation for a while ... but I will return to it at idle time ;)

... there is additional statistics ... average of extra runs ... the runs not finished until next top phase.
(6260.80 for the observers only is average of runs where third counter phase was run, and 6668.00 is average of combination with Rezyk when 2nd top phase was run ... this is average of bigger sample and even with that it's much bigger ... this makes it evident that observers are much valuable than crown phase reduction.)

I am near to declare this algorithm as the current best one.
Comparison to the two level counting scheme:

3500.79 3500.79  3468.37  3468.37 283705 283705 9:0:14,6:0:11,5:0:10,5:1:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,4:1:9| 2015,1744,481

----------

current state:

3474,02 3471,07  3463,48  3463,48  3137   3137 6242,02    0,00 7:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,5:0:6,5:0:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5|1702,581,379|465,377,371,298|325,317|278

The experiment is very unstable ... we should wait a while ...
3478,28 3476,06  3469,15  3469,15  3365   3365 6277,57    0,00 7:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,5:0:6,5:0:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5|1702,581,379|465,377,371,298|325,317|278

3489,87 3489,30  3461,97  3461,97  5662   5662 6283,94    0,00 7:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,5:0:6,5:0:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5|1702,581,379|465,377,371,298|325,317|278
And I should run the experiment also for 8 counters on the bottom level ... I am currently doing it ... it's even more promissing!

And the winner is :):
Current state for 8 counters /\//////...:
3474 is the average of all 413151 simulations run on all mutations of parameters.
3467 is the average of all 179786 simulations run after last "global kill" on all mutations.
3455 is the average of all 28031 simulations on the listed gen (the most successfull to the population size gen)
3456 is the average of all 27555 simulations after last "global kill" on the gen.
5619 is the the gen average on the extra long runs (being 3 times on level 0)

Actually there is another very promissing gen run 16242 times with the average 3445,5

3473.98 3466.73 413151 179786 3454.98  3456.22  28031  27555 5619.40    0.00 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|271,277|278
3445.50 16242 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|271,280|270

And the fresh ones:
3471.92 3465.78 551778 138627 3449.93  3455.21  29862 13620 5602.37    0.00 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|271,280|270
3422.49  1635 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|276,280|270
The 16 counters are much worse:
3494.61 3494.18 295327 ? 3473.94  3473.94  10946  10946  10946 6345.38    0.00 7:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,5:0:6,5:0:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5|1702,581,379|465,377,380,298|325,317|282
3454.47  1660 7:0:9,6:0:8,5:0:7,5:0:7,4:0:6,4:0:6,4:0:6,4:0:6,4:0:6,5:0:6,5:0:6,5:1:6,5:1:6,4:1:5,4:1:5,4:1:5|1702,581,382|465,377,380,298|325,317|287
I have stopped the simulation for 16 counters as it was evidently beaten by 8 counters. May be I will rerun simulation for two level counting to let it stabilise more ...

Actually there were some more simulations ... last state was
?      3485           ? 1000204          ?       3467          ? 315234 ? ?
9:0:14,6:0:11,6:0:11,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,3:1:8|1973,1663,404
And this seems to be beaten.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Mar 29th, 2008, 12:41am
Final state of simulation for two level counters:
3491.09 3494.29      531541      118593
3460.19  3475.24  20125  20125    485 8:0:13,6:0:11,5:0:10,5:0:10,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9|2005,1690,415
3457.26  3459.34  14606  14606  12580 10:0:15,6:0:11,5:0:10,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,3:1:8|1980,1668,405
3452.66  9315 9:0:14,6:0:11,6:0:11,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,3:1:8|2059,1663,412

(First gen was most simulated in the history of 531541 simulations with total average 3491.09, 2nd most after last reset (118593) simulations (with average 3494.29) and third most in the last small round)

Current state of simulation for 0 level counters and 8 binaries with observers with /\////.. order of binary levels:
3469.47 3466.15      944088      347990
3449.73  3430.83  30530  30530    318 5604.04 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|271,280|270
3444.24  3445.34  24387  24387  23048 5601.52 0:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|278,277|265
3446.78   756 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2314,574,440|364,373,299|279,284|298

... actually the most used gen is the same
944088 simulations in total with average 3469.47, 347990 simulations after the last reset with average 3466.15.

Current winner is /\//// 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|278,277|265
with average near the bottom of the range 3445-3466.

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Apr 3rd, 2008, 1:09pm
I have a new solution(I think) but it may be AlexH's.  I want to make sure no one has thought of the idea before I try and make the code because it will take me a while.  Anyways could someone explain AlexH's leadless binary solution?  because I  think that may be my solution I can find his solution in the thread though I only find it mentioned in this post http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=350#363

Anyway I'll explain my solution and someone can tell me if its been posted.

So I was thinking of the solution where there is one leader, and he counts everyone once and then announces the win.  But I realized that if a prisoner turns the light on there is only a 1/100 that the counter will go in the next day.  So I thought well if there are two counters that becomes 2/100 which is twice as good.  But with 2 people with 50 tokens, there has to be a way for them to communicate with each other that they each have 50.  What I noticed is that like in the original Paul Hammond's Multi-stage counting scheme you had to designate a lead counter that would count the other assistant counters.  But when there are only two counters both can send there tokens and both can receive.  So both are lead counters.  So my solution is basically having 8 or 16 counters (I'm not sure which would work best.)  Use Gypo's Stage 0 method of distributing the badges.  Thing to note (badges will have to be different sizes.  So if using 16 the first 4 badges hold 6 (not including them selves) and the rest hold 5.  You can only pass a full badge so it won't matter that they are different.
In my example I will say that we are using 8 counters.  Also I don't know what the stage lengths should  be yet so we will just assume they are there and we will eventually get through to the next stages.

Ok After the stage 0 which should last  32 days  Then starts stage 1 which is like the other stage 1s where the counters count and fill badges.

After Stage 1 you have stage2, stage 3, and stage 4
We will assume that all the badges are filled.
Stage 2
What happens is half the people pass the badges and half the people receive them.  So if a counter sees the light is off and he has an odd amount of badges and at least one of those is filled, he turns it on and drops a badge.  If a counter sees it is on and he has an odd amount of badges he turns it off and picks up the badge.

So hopefully we end up with 4 people both with 2 full badges

Eventually we will get to Stage 3 which is just like stage 2, except you only pass if you have 2 complete badges. Now we have 2 people each with 4 full badges

Then Stage 4 if a person has 4 full badges and the light is off he turns it on and drops the badges.  If a person has 4 badges and he sees the light on he picks it up and can declare victory, if he has 4 full badges as well.  That person should have at most 1 unfilled badge.

If there wasn't a win by stage 4 go back to stage 1.

Anyway I think you can see what happens.
So do you think this would be an improvement?  It makes it so each counter can count each other instead of one designative lead counter.  One problem I see is that if the it repeats by going back to stage 1.  Then there could be wasted days in the other stages.  For example.  Lets say 4 people have unfilled badges and 4 people have filled.  After stage 2 we would have 4 people with 1 filled and 1 unfilled.  Now when it gets back to stage 2, nothing will happen because you can only pass 1 badge.  So that stage was a complete waste of time.

I'm interested in what you think of this solution.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Apr 3rd, 2008, 2:52pm
Your solution is on the right way, but the way is much longer ...

I will guess this solution will long around 3900http://www.ocf.berkeley.edu/~wwu/YaBBImages/symbols/mp.gif100 days in average.
Two stages counting is faster because the most expensive part of the phase is distributing last few tokens/badges and there is no such high risk to be in a wrong phase.

The solution proposed by me differs from yours by observers stop method. This method adds to the system very high level of stability actually its pros are bigger than cons corresponding to cost of too many levels.

Observers stop which can be used on only binary phases allows prisoners not having badges to remain active. Each observed swith on during level with badges of size 2k means at least 2k badges are collected. Each observed switch from on to off during level with badges of size 2k means at least 2k+1 badges are collected and left the stage with badges of size 2k. Such observations can be in very short time summed up to know all badges were already collected (advantage is that an arbitrary prisoner can declare stop).

My first attempts were with binary phases with badge sizes x,1,2,4,2,1,x,1,2,4,2,1,x,1,2,4,2,1,x .... (or ending on level 8, x ... counters phase).
Crucial brakthrough was when I changed the strategy to sequence x,1,2,4,2,1,x,1,2,4,x,1,2,4,x,...
The downward phase is very important to spread the knowledge ... typically the upward phase ends with (one 8 badge in 16 badges case), one 4 badge, one 2 badge and one 1 badge, remaining badge was not filled yet. This leads to situatin most of the time in downward phases the light is on ... and several prisoners know at the end at least one 1 badge is missing. If the prisoner responsible to collect the badge is among them, he will declare the victory as he creates the badge. If he is not among them, typically soon after the on-off on level 1 the victory is declared. (Actually in most cases the 4th phase is the last and this is not exception when the 3rd phase is last.)

It seems this strategy with well chosen parameters has average around 3450 beating two level counting by around 10-15 days.

Here is the list of days of last few experiments with the "most spread gen".
4572, 3155, 4745,  3458,  4429,  2871,  2923,   2892,  3602,   3247,  3206,   3635,  3094,  2877,  2817,  2888,  2784, 3641,  2846,  2955,  2823,  3680,  2838,  3186,  3568,  3656,  3421,  3359,  2786,  2721,  4129,  3777,  3073,  2915,   3051,  4195

on 04/03/08 at 16:09:43, Wardub wrote:
 I've got a question, is mine different that Alex H's?  Could someone explain his.  Also Hippo I am not fully understanding you solution.  Where in this thread is it so I can look it up.

Original binary AlexH algorithm didn't used the initial counting phase, and two counting levels didn't use binary phases.

Ideas of my algorithm can be found on pages 21,22,23,24,25.

3466.19 3455.05     2156391       27756
3448.82  3473.46  34868     35 5621.36    0.00 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2277,559,415|356,364,292|278,277|265
3418.30  3418.30   1860   1860 5589.36    0.00 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2292,566,421|361,369,297|276,282|279
3448.93    81 10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10|2220,542,402|353,353,279|261,276|268

There are only two prephase patterns for all the most succesfull gens:
10:0:17,8:0:15,6:1:13,5:1:12,4:1:11,4:1:11,4:1:11,4:1:10 and
10:0:17,7:0:14,6:0:13,5:0:12,4:1:11,4:1:11,4:1:11,5:1:11

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Apr 3rd, 2008, 4:09pm
Ya thinking about it a little more I would say my multiple stages would be come pretty inefficient if one of the stages failed.  Which would mean each stage would have to be longer.  Anyways I still plan on writing the code for fun.  I've got a question, is mine different that Alex H's?  Could someone explain his.  Also Hippo I am not fully understanding you solution.  Where in this thread is it so I can look it up.

One last thing, I'm not the greatest programmer and I only have java.  I'm thinking I will make a class prisoner.  Is there a way in my main to create 100 different prisoners?  with like a for loop or something.  other wise I will have to do something like prisoner prisoner1 = new prisoner a total of 100 times.  Thanks.

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Apr 6th, 2008, 8:46pm

on 04/03/08 at 14:52:25, Hippo wrote:
 Your solution is on the right way, but the way is much longer ...I will guess this solution will long around 3900http://www.ocf.berkeley.edu/~wwu/YaBBImages/symbols/mp.gif100 days in average.Two stages counting is faster because the most expensive part of the phase is distributing last few tokens/badges and there is no such high risk to be in a wrong phase.

WOW I finally finished the program and I got 3905.46 or something after only 50,000 iterations.  I think my program is slow but I'll run it over night when I go to bed.

So it wasn't even close to the best solution so far.  But I was happy it made it under 4000 days.

I have another idea but it will likely be over 4000.  It has three stages.  Basically after stage 0. you have 50 people with 2 tokens.  and then its like the 10 counter strategy.  I'm hoping by lowering the amount of people each counter has to count will speed up stage 1.  Then stage 2 is like all the others with the crown.  This probably won't work but I'm trying to come up with new ideas atleast :)

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Apr 7th, 2008, 7:46am
I guess 4250\pm 100 :).
You have lost snowroll prephases, reducing number of tokens to collect say to 100*2/3 using only say 100*2/3 days.
Actually collecting first 50 tokens requires time much smaller to time to collect the remaining 50.
The phase switching cost is higher than the gain.

The problem are phases with small number of active prisoners. The expected dalay between their visits is 100/a where a is the number of active prisoners. The phase switching problem is that you don't know during planning the phase lengths which level will be the lowest which was not finished yet. All runs where the phase ended prematurely must wait for all other levels to be able to continue. The most costy is gathering of the last tokens/badges on the level. So the levels cannot be short even when we expected only small number of tokens is left here. Shorter binary phase than 150 is nonsense, 300 (for expected two badges) is enough. For counter phase less than 200 is nonsense, 400 seems to be enough(depends on number of levels ...).

on 04/08/08 at 21:22:41, Wardub wrote:
 Do you have code in java of your method?  I assume not.  O well.

Actually not. I have codded it in fox (Yes I know not the best choice). The code is not very nice ... :(

on 04/08/08 at 21:22:41, Wardub wrote:
 EDIT: Hippo I see that you have been testing methods.  I would also like to test the two leading solutions, which I believe are yours and the SMQ and Leonid.  Could you tell me the cycle lengths for each stage?  Its probably because its late but I can't seem to find you solution.  Is it a build off of a previous one?  and which one.  Thanks for the help.

The best so far parameters can be found on this (25) page.
The prephase lengths are included in the length of the first phase. On the page 23 the decodding of the string is described ... the Rezyk post.

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Apr 8th, 2008, 9:22pm
Actually I got my method in around 3980 days.   Under 4000 again  ;D.  And I understand why the methods don't work as well.  Because their is a bigger risk of one of the stages failing with more stages.  I haven't really thought of a way to improve the second portion so I wanted to try and speed up the first stages and hopefully it would be enough to compensate for the later stages.  Didn't work.  Anyways I haven't been able to look at your solution yet, but I plan on this weekend when I have time.  Do you have code in java of your method?  I assume not.  O well.

EDIT: Hippo I see that you have been testing methods.  I would also like to test the two leading solutions, which I believe are yours and the SMQ and Leonid.  Could you tell me the cycle lengths for each stage?  Its probably because its late but I can't seem to find you solution.  Is it a build off of a previous one?  and which one.  Thanks for the help.

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Apr 17th, 2008, 9:21pm
Sorry for double post.  HMM I seem to be having trouble replicating results of Gypos method with SWFs improvements.
I am getting around 4000 days. When the expected is under 3500 days.  I am really curious why this is.  I am using {6,5,5,5,5,5,4,4,4,4} for stage 0 cycles and badge sizes of {12,11,11,10,10,10,9,9,9,9} I am using 2000,1600,300,300 for stage cycles.  I am really confused, and I would really like to write a program that can get under 3600 days.

Ill post my code.  Its in java and not the  most optimally written.

Code:

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Apr 17th, 2008, 9:22pm
second part of class and the main that runs the program

Code:
 // ------------------------------------------------- Stage 2 -------------------------------------// Counter with crown counts up filled badgess       public inmates[] stage2(inmates[] prisoners, boolean lightBulb, boolean last){   numberOfDays++;   boolean lightState = lightBulb;           int Select = (int)(Math.random()*100);           if(lightState == true)           {   if(prisoners[Select].crown || (last))   {   prisoners[Select].token+=BADGES[0];   lightState = false;   prisoners[Select].badges++;   prisoners[Select].badge = true;   }   }   else if(lightState == false && (!last))   {   if((prisoners[Select].badge) && (prisoners[Select].token>= BADGES[0]))   {   lightState = true;   prisoners[Select].badges--;   prisoners[Select].token-=BADGES[0];   if(prisoners[Select].badges == 0)      prisoners[Select].badge = false;   }   }   if(lightState == false && last)   {   if(prisoners[Select].overCount > 0)   {   lightState = true;   prisoners[Select].overCount--;   }   else if(!prisoners[Select].badge && prisoners[Select].token > 0)   {   lightState = true;   prisoners[Select].token--;   }   }   setLight(prisoners,lightState);   setDays(prisoners,numberOfDays);      return prisoners;   }   public boolean checkWin(inmates[] prisoners){   for(int i = 0; i<100; i++)      if(prisoners[i].token==BADGES[0]*BADGES.length)         return true;   return false; }    public boolean check1(inmates[] prisoners){for(int i = 0; i < 100; i++)   if((!prisoners[i].badge && prisoners[i].token >0) || prisoners[i].overCount>0)      return false;return true;}   }//START OF MAIN ------------------------------------------------------------public class escape{public static void main(String [] args){        int times = 10000;        double fail1=0;        double fail2=0;        double finalCount = 0;        int runTime = 0;boolean lightBulb = false;boolean Game = false;int[] winCount = new int[times];        for(int j = 0; j < times; j++)        {Game = false;    runTime = 0;finalCount = 0;int [] Cycle = {2000,1600,300,300};inmates[] prisoner = new inmates[100];for(int i = 0; i < prisoner.length; i++) prisoner[i] = new inmates();prisoner = prisoner[1].stage0(prisoner);            while(Game == false)            {         for(int i = 0; i < Cycle[0]; i++)         {         lightBulb = prisoner[1].getLight();          if(i==Cycle[0]-1)              prisoner = prisoner[1].stage1(prisoner,lightBulb,true);         else             prisoner = prisoner[1].stage1(prisoner,lightBulb,false);         if(runTime == 0)          {     if(prisoner[1].checkWin(prisoner))     {     runTime++;     winCount[j] = prisoner[1].getDays();     Game = true;     }     }         }          Cycle[0] = Cycle[2];          if(!prisoner[1].check1(prisoner))             fail1++;         for(int i = 0; i < Cycle[1]; i++)         {         lightBulb = prisoner[1].getLight();         if(i==Cycle[1]-1)             prisoner = prisoner[1].stage2(prisoner,lightBulb,true);         else             prisoner = prisoner[1].stage2(prisoner,lightBulb,false);        if(runTime == 0)        {     if(prisoner[1].checkWin(prisoner))      {     runTime++;     winCount[j] = prisoner[1].getDays();     Game = true;     }     }       }       Cycle[1] = Cycle[3];       if(!prisoner[1].checkWin(prisoner))          fail2++;     }  }   for(int i = 0; i < times; i++)        finalCount+= winCount[i];     System.out.println(finalCount/times);

I left off some of the stuff at the top and bottom because they were useless.  My program runs fine but I can't replicate their days.  I would like to write a program that can get under 3600 days, what method should I use? preferably easiest to code for a beginner and in java.

Ok my code came out funny so Ill just attach it as well.  I would really appreciate it if someone could try and run my program(it does work) and try and figure out if my answers are wrong or not.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Apr 18th, 2008, 12:31am
I am not an expert on java, but there are some strange things in your code.
1) You use BADGES[0] more often I would expected.
The conditions to check don't require it.
2) There is no need to distribute information about current day to all prisoners. Only the selected one got new information and can stop the process so there is also no need to ask each prisoner if he wants to stop. So it is sufficient to update current date for the selected prisoner.
3) Actually you don't need to maintain countsize and compare tokens with countsize. Equal comparision can be obtained by lowering the tokens by the value to be added to countsize and compare to zero instead. Creating third counter ... overcount I didn't catch at all.
4) There are some possible improvements in prephases ... 2nd-3rd day hook and redistribution days, but these can short the computation by say 3-4 days.

Especially 1) makes it difficult for me to check the correctness of the code. But I would expected there is a bug. For the parameters you have described the average run time should be under 3700
(probably near 3500).

Title: Re: 100 prisoners & a light bulb
Post by Wardub on Apr 18th, 2008, 11:38am
Let me try and explain it a little.  And I am no means an expert at java either.

1.) I have different size badges, but it is easier to compare if all the badges are the same size.  So BADGES[0] is the size of all badges.  Then it adds fake tokens to prisoners that get smaller badges.   So everyone counts up to BADGES[0].  This means in my program there are more than 100 tokens but I am fairly sure it runs correctly.

2. I know this, and the prisoner doesn't really keep track of anything.  It more or less makes sure that everyone is on the same day, and that the lightbulb is in the right state every time someone enters.   I know its inefficient but it was the easiest way I could come up with.  No prisoner gets any extra information by this.

3.  I don't think i used countsize or a lot of variables.  I just added some that I thought I might need and ended up  not using them.

Over count is on the last day of stage 1.  If the light is on and the person selected has a full badge then they need to pick up that token or else it will be lost.  But then they have to many tokens.  So overcount is basically a count of tokens more than their number of (badges*badgesize) I probably could of just added the token.  And then added an if prisoner.token>badgeSize) then turn light on and subtract a token.  But I didn't think of it right away.

4. Not sure what you mean by 2-3 day hook and redistribution.

To clarify a few things.  I first wanted to replicate gypos method, but I thought I could improve it by changing the cycle lengths in stage 0.  I ran  some simulations and it takes about 13.2 days on average for a prisoner to go into the room twice the first time.  So I was going to make the first cycle be 13 days and progressively decrease it.  BADGES[0] will always be the badge size.  This means the prisoner with the crown must count up to BADGES[0] * number of badges.  When it assigns  badges the prisoner gets how ever many  people have been since the beginning of the cycle + (Size of the badge[0] - badge[j] where j is which badge it assigns.)  So a little example with
int [] CYCLES = {6,5,5,5,5,5,4,4,4,4};

first  badge assigned gets however many passed plus 12-12.  Then the next person gets however many have passed + 12-11.  So he gets an extra token and now counts to 12.  this happens for everyone so everyone counts up to the same amount, and it is easier to check because now a badge is full if tokens >=BADGES[0]

Hope that makes sense.
And thanks for trying to help me out.

Edit:  I believe it works correctly but I am getting a lot more failures I believe after the stage 1 then others are getting and this is raising the average.  I think the problem might be in stage 0 or stage 1.  Could you perhaps see on average how many people are counted after the stage 0?  I would like to see if that matches.  I gotta go now, I'll come back and post how many people on average have no tokens after stage 0 completes.

Title: Re: 100 prisoners & a light bulb
Post by Iceman on May 22nd, 2008, 10:26am

Quote:
 Before this whole procedure begins, the prisoners are allowed to get together in the courtyard to discuss a plan. What is the optimal plan they can agree on, so that eventually, someone will make a correct assertion?

Who cares about an optimal plan if it will work after, perhaps, 50 years? I'd wait for no more than 10 years. So within this decade I'd be sure to make the assertion if the warden picks me.

Title: Re: 100 prisoners & a light bulb
Post by rmsgrey on May 23rd, 2008, 5:06am

on 05/22/08 at 10:26:12, Iceman wrote:
 Who cares about an optimal plan if it will work after, perhaps, 50 years? I'd wait for no more than 10 years. So within this decade I'd be sure to make the assertion if the warden picks me.

Current "best" approaches have expected run-times of less than a decade.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Nov 22nd, 2008, 11:33pm
I have spoke to frends about the history of improvements of the problem what made me find one more improvement in the algorithm ;) ... I didin't finish all the experiments, but it's very promissing. For 8 counters with binary observers, /\///... order of phases and fine tuned snowball prephases my average of the enitre population of mutation algorithm is under 3433 days.
Best gens so far are around 13 days better.

The trick should be tested on 2 level counters scheme as well on 16 counters with bineary observers ... improvements may be even better for these cases. So stay tuned :)

So what was the improvement?:
The trick where "2nd night of the snowball signalling the light off means there is badge and one less token compared to light on signal" can be used for 1st night of the secondary snowballs.

This wouldn't be good enough if we don't prevent double badge situations. Taking 2nd badge after 1st subsnowball night is devastating. Trick is in increasing the number of tokens by 2 and letting light on in such situation.

This double badge prevention can be more generalized  ... if a prisoner with 2 badges is near the bulb in prephase when light is off, he switches it on and leaves badge and appropriate number of tokens in the room.

Actually there is much better generalisation I didn't implement yet ... almost what Rezyk described in "passing terminology".
Each night of all snowball prephases has defined amount of badges and tokens represented by light on signal and amout of badges and tokens represented by light off signal. When prisoner enters, he collects the amount corresponding to light status and checkes if he is able to leave the light on signal of the following night. If he is "able", he lights on and leaves the badges and tokens according the next night signalling. To be "able" means he has (either more badges or equal amount of badges and tokens*) as the next night signalling.

This generalisation makes improvement even in situation prisoner with one badge enters in the middle of interrupted snowball (light off) and he can leave everything he collected to let the snowball continue (rare case, in this situation with snowball running it's better to continue than interrupt it, so this is better to restart than let it interrupted).

One more trick not implemented yet:
The redistribution subphases neednot signal the same number of tokens as finished snowball.
They are to prevent 2 badges in one prisoner hands ... to distribute 2 badges goal to 2 prisoners.
We know that 2nd badge was collected by full snowball (we don't take 2nd badge before snowball end),
the first one neednot be. Sending all tokens collected in the already finished snowball typically creates 2nd goal smaller.
It seems to me decreasing the signal by 1 token would improve the goal distribution (when goals for fully successfull snowballs are chosen almost equal).

----------------
* actually if expected collection in the rest of the snowball phase is greater than the tokens he should keep, it's better to restart even in this case. So each badger in such situation computes the expected collection :) ... or it can be precomputed. (I don't expect the number of tokens he keeps (which would be much less than expected goals) make big impaction to "lighting on" behaviour in collection phase.)

For the case 10:0:17,7:0:14,6:0:13,5:0:12,4:1:11,4:1:11,4:1:11,5:1:11 i have made some calculations ...
if the badger defined by the first snowball gathers 3,4,5 or 6 tokens, he can restart the 2nd snowball even 2nd day when he must became nonbadger with upto 3 tokens. This is the only case nonbadger with 3 tokens may be created in "optimal" algorithm. Badger with 3,4 or 5 tokens can restart 3rd snowball creating nonbadger with upto 2 tokens.
Badger with 3 or 4 tokens can restart 4th and 8th snowball creating nonbadger with upto 1 token. Finaly badger with 3 tokens can restart 5th, 6th and 7th snowball without remaining tokens. It seems the condition is the number of remaining nights of snowball after restart night is sufficient to be more than number of tokens left in nonbadger hands, but for wrongly chosen snowball lengths the result would not be so easily described.
----------------
After some experiments: The cons of restarting is increase of probability doublebadger is created. This is why I restart with remaining tokens only when the remaining length of snowball is at least one more night longer now.

Pessimistic restarting ... at most 2 tokens remains in prisoner hand when becoming nonbadger,
At least 2 more nights of snowball than remaining tokens in prisoner hand (if some token remain).

For 2 level counting 8:0:13,6:0:11,5:0:10,5:0:10,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9|2081,1743,444 gets around 3505, average of whole population 3532. Does not seem to converge to under 3460.
(5:0:12,4:0:10,4:0:10,4:0:10,4:0:10,4:0:10,4:0:10,4:0:10,4:0:10,3:0:9|1969,1600,300,300 got around 3670) But I should rerun it on the gen 9:0:14,6:0:11,6:0:11,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,3,1,8|1973,1663,404 having best results (~3467) without snowball optimisation.

For 8 counters with observers binary /\//// 10:0:17,7:0:14,6:0:13,5:0:12,4:1:11,4:1:11,4:1:11,5:1:11|2234,556,418|353,366,311|272,282|292 gets around 3414, average of whole population 3427.

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Nov 26th, 2008, 6:49am
Icarus notes about problem history (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=350#363)

History
BanderSnatch (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=0#4) - Complete cycle scheme.  Run-time = 1.0608 x 1044 days.
Captain Caveman (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=0#10) (quoting from a slash-dot site) - Single stage counting scheme ("Leader solution"). Run-time = 10418 days (28.5 years).
sjbrown (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=20#22) - Distribution scheme, stage length = 1, only the prisoner can pass his marker. Run-time ~ 8230 years (per Mattian).
S. Owen (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=20#28) - Distribution Scheme, stage length = 1 (anyone possessing a marker can pass it): Run-time 252 years (per Mattian).
Salem (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=40#43) - Single stage counting scheme with 100 day "snowball" round. Run-time =9367 days (~25.6 years, per Mattian).
AlexH (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#66) - Single stage counting scheme with short "snowball" round. Run-time = 9321 days (per Mattian).
Paul Hammond (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#73) - Multi-stage counting scheme (future cycles start from scratch). Run-time = 3964 days (~10.8 years, per Mattian).
AlexH (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#74) - Multi-stage counting scheme (future cycles are continuations, stage lengths vary between cycles). Run-time ~ 3600 days
AlexH (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=60#74) - Leaderless binary counting scheme. Run-time ~ 4250 days
biwema (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=100#104) - Counting scheme with mixed-value tokens: Run-time = 3600 days.
SWF (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=120#124) - Counting scheme with multi-leader snowball round (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=120#133). Run-time = 3535.6 days.
Rezyk (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=180#197) - Counting scheme (consolidation round, greedy leader, 2nd cycle degeneration). Run-time = 3532 days.
gypo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=200#202) - Counting scheme (borrowing against badges). Run-time = 3489 days
Paul Hammond (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=240#247) - Distribution scheme with stage length >1. Run-time ~ 54,000 days (148 years)
rmsgrey (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=240#252) - Distribution scheme with varying stage lengths between cycles: Run-time ~ 53,000 days (145 years)

As Icarus is out of there ... I should insert myself into the table... :).
Leonid Broukhis + SMQ (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=475#494) - improved gypo's 2 level counting scheme by optimisation of mutlisnowball prephases - declared around 3460 days.
Hippo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=500#520) - observers method with /\/\/\ order of binary phases added to binary scheme of AlexH. Run time around 3800 days.
Hippo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=500#521) - Bottom stage 2k counters with multiple snowballs, binary observers /\/\/\ phases above. Run time for 24 counters for well chosen parameters (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=550#556) around 3490 days. Run time for 23 counters for well chosen parameters (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=550#560) around 3490 days.
Hippo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=600#600) - Bottom stage 23 counters with multiple snowballs, binary observers /\//// phases above. Run time around 3465 days.
Hippo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=600#614) - Badge delay in first possible fail night in multiple snowballs applied to 8 counters with binary observers /\////. Runtime under 3430 days.
Hippo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=600#621) - Badge delay in first possible fail night in multiple snowballs applied to 12 counters with binary observers /\//// and ternary top phase. Runtime under 3390 days. Algorithm (with small diferences /\/\) actualy mentioned on Hippo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=500#522), but rejected without tests at that time.
Hippo (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=600#614) - Badge delay in first possible fail night, pessimistic restarting in multiple snowballs applied to 2 level counting scheme so far above 3490 (far from improvement from declared 3460).

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Dec 2nd, 2008, 2:39am
I have rerun the algorithm with pessimistic restarting and badge distribution dalay of first fail night  on the gen 9:0:14,6:0:11,6:0:11,5:0:10,5:1:10,4:1:9,4:1:9,4:1:9,4:1:9,3,1,8|1973,1663,404. And first few simulation had average around 3430, but a serie of long runs occurs and the average went to around 3530. May be parametrisation of phase lengths is not optimal. If first phase fails, it's probable one counter remains, but it's remaining goal may be bigger than 1 (especially for double badger case). On the other side, for 2nd level, the probability the crown goal remain higher than 1 is much smaller.
May be section for bottom phase lengths and section from top phase lenghts may improve the behaviour (3 values in  first section, 2 values in second one).

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Dec 2nd, 2008, 3:26pm

on 11/26/08 at 06:49:07, Hippo wrote:
 Leonid Broukhis + SMQ (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1027805293;start=475#494) [...] declared around 3460 days.

You seem skeptical. ;)  Working code attached; the reported mean is 3460.43 days for 10,000 trials and 3464.61 days for 1,000,000 trials (with a standard deviation around 673).

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Dec 2nd, 2008, 5:57pm
The problem with a simulation is with the quality of pseudorandom generator.
I am surprised with the inconsistency of my experiments on 2 level counting. ... previous experiments with best gen around 3467 but population average around 3485. And current results (after I hope improved snowball phases) worse. I haven't run the experiments now for long time (around an hour) as the binary method looked much more perspective (I hope to beat even 3400 days, but 3410 is much more realistic result). I had implemented it in slow environment and it takes around 3 days before the gen stabilises.
It will be rerun later.

Probably I should compute standard deviation as well...

There is slight difference in my encodding of phase lengths ... according to your code, I should use gen ...|2009,1600,300,300.
I suppose the code is from may 2006 so you fill badge sizes by positive tokens collect badges to given count as was recomended at that time ... I would use negative token counts instead of setting badge sizes. Actually when filling 2 badges, it does not matter one is already filled so you can move goal to only one of them.... hold one of them and send others. The first snowball fail possibility dalay was not implemented even for the 2nd night.
(snowball restarting was not implemented, too) ... so I hope for more than 10 days of improvement.

P.S.: Your signalling between two prephases would be described by 1 day goal reassignment in my terminology.
The 0 in 9:0:13 would mean the night "between two prephases" is used by snowball signalling ... badger selected last day should send one of his tokens back, if selected earlier the prisoner is counted. ... This is the number of nights of signalling method I use in the gen.
[/edit]

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Dec 2nd, 2008, 7:15pm

on 12/02/08 at 17:57:34, Hippo wrote:
 The problem with a simulation is with the quality of pseudorandom generator.

Well, one of the problems, at least.  The code I attached above uses the Mersenne Twister (http://en.wikipedia.org/wiki/Mersenne_twister) generator, which was specifically developed for running Monte Carlo simulations where the subtle correlations of a simpler generator could be influential.

Quote:
 Probably I should compute standard deviation as well...

Well, I'm not sure it's the most useful measure here, since the staging groups results together into peaks.  When I get a chance I'm going to unpdate my code above to compute std. dev. for each stage separately and see what that looks like.

I haven't looked at it in a while, but I'm not convinced that Leonid searched the entire parameter space of that algorithm: maybe there's another day or two to be found in it yet. ;)

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Dec 6th, 2008, 1:06am
Thanks for the link, I will replace the generator and we will see the difference ... after some time ;)
Hmm, making Uniform distribution from MT19937 by modulo (throwing away small number of values to make each class of the same size) ... the results of simulation give population average around 3526 and best gen so far around 3504
(started by gen corresponding to your algorithm).

... I should check my code carefully.

... after a long while ... (simulation of more than 3 500 000 games) gives the total average 3428, with the most spread gen
10:0:17,7:0:14,6:0:13,5:0:12,3*(4:1:11),5:1:11|2236(10+7+6+5+3*5+6+2187),559,421|356,371,317|273,286|292
having around 30700 simulations with average 3416.

All the best gens give the same prephase. The gen with
|2229(49+2180),579,430|368,375,327|289,303|309 having around 30000 simulations with average 3412.

(Of course these simulations are on 8 counters with binary phases in order /\///// with observers and 8 snowballs each with first fail night hook)

The simulations are with MT19937 generator used to select a prisoner by mod 100 operation after throwing away some random values to make sure each mod class has the same number of results.

The situation was not changed until the end of simulation process. (the average of the 2nd gen around 3412 with 31023 simulations, total average around 3427, average around 3416 for most spread gen with 31175 simulatios).

Fourth most spread gen (with 26168 ) simulations had average around 3407 (10:0:17,7:0:14,6:0:13,5:1:12,3*(4:1:11),5:1:11|2223,553,421|352,363,310|273,281|296).

Title: Re: 100 prisoners & a light bulb
Post by Hippo on Feb 17th, 2009, 2:00pm
New progress noted in n prisoners and k state switch (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1177584051), I have started experiments with counters with binary /\//// observers and with ternary top phase (first fail hook in snowballs, and carefull snowball restarting) and I was very surprised by success of this strategy.

I got under 3390 average of all simulations, (3377 after last of 3 restarts) most spread gen had average around 3355:
3:0:9,3:1:9,3:1:9,3:1:9,3:1:8,3:1:8,3:1:8,3:1:8,3:1:8,3:1:8,3:1:8,3:1:8|1928,657,665|440,442,439|506,512|378

I was very surprised by very short snowballs with big prevention of doublebadge ... it was common to all most successfull gens.

on 01/17/08 at 06:50:18, SMQ wrote:
 Although I can't find the paper at the moment, I believe the single leader solution to the IBM version (http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/challenges/July2002.html) has indeed been proven optimal.--SMQ

Actualy yes and no, the nC2 case has better solution they use single counter to count 2*n tokens. Better solution is to count to n tokens. (It requires waiting for reset not to count the possible initial switch on. Only the counter can change the switch state at beginning, other prisoner starts signalling after observing switch state change. This is why counter switches on with nonzero probability (switching always off). I would switch as counter on with probability (n-tokens collected)/n, but this may not be optimal). I would guess this method took around n(n+4) visits in average compared to around 2n(n+1) of IBM.

Title: Re: 100 prisoners & a light bulb
Post by cheeku on Mar 10th, 2009, 3:42am
Hi This could be one of the possible solution:
100th Prisoner will be the coordinator who will finally announce that all 100 Prisoners have visited the room.
Algo:
Everyone has to switch on the bulb once if bulb is off.
And 100th prisoner has to switch off the bulb whenever he enter the room and finds it ON.

eg:Lets say, 21st prisoner comes on the 1st day => he will switch ON the bulb.
51th Prisoner comes on the second day. He wont do anything and keep the bulb ON...
This will continue till the turn of 100th prisoner comes and he switch it OFF.

Now 21st prisoner turn is over and he wont do anything now onwards whatever be the status of bulb.

And 100th prisoner will keep counting whenever he finds the bulb ON and would announce when he does it 99 times.
:)

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 10th, 2009, 5:20am
That is indeed one possible solution, known around here as the "single leader" solution.  On average it will take almost 30 years for the prisoners to be freed that way.

Can you think of any possible improvements? ;)

--SMQ

Title: Re: 100 prisoners & a light bulb
Post by SMQ on Mar 10th, 2009, 6:58am
Before this thread spills over to yet another page -- 25 pages is enough -- I'm going to lock it and start two new ones: one for general discussion (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1236693480) and one for advanced solutions (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi?board=riddles_hard;action=display;num=1236693415).

--SMQ