in reply to Suggestions for writing a Perl application

Demonstrate the solution to this puzzle in Perl:

A prison warden summons three convicts before him and suggests that whichever of them can pass a certain test shall be set free. 'Here are five discs,' he says, 'three white and two black. I shall fix one of these discs on each of your backs without telling you which color I select. You are not allowed to speak or to use a mirror, but you can look at one another ('s backs). The first one to guess the color of the disc he is wearing can go free, providing he can explain how he arrived at his conclusion.'

The prisoners agree to take the test, and the warden puts a white disc on each of their backs. After looking briefly at one another ('s backs), they all leave the prison yard together (i.e. they pass the test). Each one, by the same argument, has realized that he was wearing a white disc.

So the task, then, is to figure out how the prisoners discovered that they each were wearing a white disc.

  • Comment on Re: Suggestions for writing a Perl application

Replies are listed 'Best First'.
Re: Suggestions for writing a Perl application
by Abigail-II (Bishop) on Aug 29, 2003 at 23:57 UTC
    Well, the solution is fairly simple, if you can assume the convicts are smart (which is quite bold), and they have a similar sense of "how long it would take to figure out a logic problem".

    The solution is that if two convicts wear a black disk, the third convict knows he has a white disk. But from looking at the backs of the other convicts, the convicts know that there is at most one black disk - and if there's a black disk, it's on their back, and the others see a white and a black disk. However, since noone leaves right away, the ones seeing a black and a white disk will conclude their disk must be white - there cannot be two black disk, and they can leave. But this also doesn't happen, so the premises that one's disk is black is false, ergo, everyone has a white disk.

    But as I said, there's a timing problem, and the assumption the others are smart. Usually, this question is asked with perfect logican getting hats or disks to wear, and there is some timing mechanism (for instance, each of them is asked a question in a particular order).

    I don't really see a way of demonstrating this puzzle in Perl.

    Abigail

      I don't really see a way of demonstrating this puzzle in Perl.

      An algorithm should do it. The puzzle is a well-known one. Logical time is divided into three moments.

      1. the instant of seeing
      2. the time for understanding
      3. the moment of concluding

      The first prisoner to deduce the color of the disk on his own back will be granted his freedom. The correct deduction appears to depend on the hesitation of the group. "If I had a black disk, then each of the other prisoners would not hesitate to deduce immediately that he was white. Since neither has done so, I must also have a white disk." In fact, this puzzle would make a nice Perl game.