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.


In reply to Re: Suggestions for writing a Perl application by jacques
in thread Suggestions for writing a Perl application by phax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.