|
When you were a lad there was no intarweb, it was all on punched cards!
That said, when I was a lad 'bleeding edge' was mag tape.
speramus in juniperus
|
|
|
|
|
Yes I remember, but as far as I'm concerned, codeproject is about the articles (and the lounge )
Just skip the QA if it bothers you. I miss him a bit, like anyone with more brains than attitude.
Politicians are always realistically manoeuvering for the next election. They are obsolete as fundamental problem-solvers.
Buckminster Fuller
|
|
|
|
|
I've suddenly gone off my lunch
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
I heard rumour that someone went to visit the hamsters with an electric beard trimmer and a toilet tube, and gave them choice to 'pull harder for the team'
speramus in juniperus
|
|
|
|
|
Well, that would make me pick up my game too.
[I hope my boss doesn't see this ]
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Following on from yesterday's maths, here's a more logical [but still mathematical] problem.
The Prisoners:
The warden of a top security prison meets with the 23 prisoners as they arrive and he tells them:
You may meet together today and plan a strategy, but after today you will be in isolated cells and have no communication with one another.
There is in this prison a "switch room" which contains two light switches, labelled "A" and "B", each of which can be in the "on" or
"off" position. I am not telling you their present positions. The switches are not connected to any appliance. After today, from time to
time, whenever I feel so inclined, I will select one prisoner at random and escort him to the "switch room", and this prisoner will
select one of the two switches and reverse its position (e.g. if it was "on", he will turn it "off"); the prisoner will then be led back
to his cell. Nobody else will ever enter the "switch room".
Each prisoner will visit the switch room arbitrarily often.
At any time, any of you may declare to me: "We have all visited the switch room." If it is true (each of the 23 prisoners has visited the switch room at least once), then you will all be set free. If it is false (someone has not yet visited the switch room), you will all be put to death!
Devise for the prisoners a strategy which will guarantee their release.
You can easily google this, as I found it on the interweb, so play nice and try to apply some thinking. Go on, I dare you! Double dog dare you!
speramus in juniperus
|
|
|
|
|
If the switches are not connected to any appliance, then they cannot be light switches. They are simply switches.
|
|
|
|
|
Correct, they're just two switches marked "on" and "off". The strategy is what switches go where, when and why.
speramus in juniperus
|
|
|
|
|
I know the rules, but it also said they were light switches. I'm just being picky
|
|
|
|
|
Maybe they are painted in a light colour?
Or it could be that the switches in question weigh significantly less than other (heavy) switches
Anything that is unrelated to elephants is irrelephant Anonymous ----- Do not argue with an idiot. He will drag you down to his level and beat you with experience Greg King ----- I always wanted to be somebody, but now I realize I should have been more specific. Lily Tomlin, Actress
|
|
|
|
|
|
|
One of them is elected as the only person who can say "We have all visited". He is the only one who changes the left switch from down to up. As each other prisoner enters the room, if the left switch is up, and he has visited the room but not moved the left switch, he moves it down. Otherwise, he moves the right switch.
When the "special" prisoner enters the room, if the left switch is down, he changes it to up, and adds one to his mental count. Otherwise he also moves the right switch.
When his mental count reaches 23, all of the prisoners have been in the room.
|
|
|
|
|
Almost right. What if the left switch was down to start with?
speramus in juniperus
|
|
|
|
|
Shouldn't matter should it, counting to 23 is one more than required since he does not have to count himself and so will take into account the switch starting down.
|
|
|
|
|
I'm going to retract my original answer as this may be right.
The method I have is similar but each prisoner switches the left up twice and when the caller gets to 44 he says everyone has visited, this gets over the left being up to start with. But I think that you may have beaten the maths brains of IBM[^]
speramus in juniperus
|
|
|
|
|
The trouble with that approach is that 2 prisoners could visit 44 times, and 21 of them sit on their hands waiting to die...
|
|
|
|
|
No it doesn't, each prisoner only switches up TWICE, so your two visitors would only raise the switch FOUR TIMES.
speramus in juniperus
|
|
|
|
|
Maybe I need another coffee!
|
|
|
|
|
Griff was close but is foresee another problem.
I will agree they choose one person that will change a specific switch to a specific value and no one else ever will. So now lets say they choose that the prisoner counting changes the left switch ON. Now when anyone enters the room they can switch the Left switch OFF only 2 times. So when it is ON they switch it OFF until they did that 2, only the counting prisoner will ever switch the Left switch ON, and every time he does that he counts the number of times he does that. Now being that there is 23 prisoners (- 1 as the counter is excluded), the counter should switch the left switch ON 41 times. Because under worst case scenario if the first person were to switch OFF the left switch before the counter's first visit, when he counts to 41, most would have switched it twice, if not it would mean that once person only switched it once.
Loading signature...
. . . Please Wait . . .
|
|
|
|
|
I still think Griff is correct. The first time the counter goes in he effectively resets the problem to the one where the left switch starts in the up position, however he does not know if anyone has been in before him so he would not start counting until next time he visits, which is effectively the same as starting the count immediately but adding an extra 1.
|
|
|
|
|
but the dilemma remains in the counting, that is why I say he has to count to double the amount of prisoners excluding the counter times two. Safer and more secure letting everyone do it twice at so that worst case will be when someone went in and changed it before the counter's first visit, the worst case scenario would be that one person only changed it once instead of twice. Now if you are only going to do it once you will run into the dilemma of miscounting one...
Loading signature...
. . . Please Wait . . .
|
|
|
|
|
But if the left switch starts in the up position, the "counting" prisoner will never reach 23, because the other 22 prisoners will only move the switch down once each.
I think this is the reason to let everyone switch two times at most. This way you have a safe margin of 1.
- If the switch was down at the beginning and the "counting" prisoner enters first, he will reach 44 after 1 prisoner has moved the switch down once and the others twice.
- If the switch was up at the beginning and the "counting" prisoner enters first, he will reach 44 after all other prisoners have moved the switch down twice.
- If the switch was down at the beginning and another prisoner enters first, the "counter" will reach 44 after all other prisoners have moved the switch down twice.
- If the switch was up at the beginning and another prisoner enters first, the "counter" will reach 44 after all other prisoners have moved the switch down twice.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Exactly
Loading signature...
. . . Please Wait . . .
|
|
|
|
|
Use a pen to mark the count each time one enter the room write on wall and add the counter, once the counter reach 23 they are all visited.
|
|
|
|