my prose explanation may be unclear but i think it's correct. look closely at the example code. running it gives:

pearl #0 was light. found in 3 tests.
pearl #0 was heavy. found in 3 tests.
pearl #1 was light. found in 3 tests.
pearl #1 was heavy. found in 3 tests.
pearl #2 was light. found in 3 tests.
pearl #2 was heavy. found in 3 tests.
pearl #3 was light. found in 3 tests.
pearl #3 was heavy. found in 3 tests.
pearl #4 was light. found in 3 tests.
pearl #4 was heavy. found in 3 tests.
pearl #5 was light. found in 3 tests.
pearl #5 was heavy. found in 3 tests.
pearl #6 was light. found in 3 tests.
pearl #6 was heavy. found in 3 tests.
pearl #7 was light. found in 3 tests.
pearl #7 was heavy. found in 3 tests.
pearl #8 was light. found in 3 tests.
pearl #8 was heavy. found in 3 tests.
pearl #9 was light. found in 3 tests.
pearl #9 was heavy. found in 3 tests.
pearl #11 was light. found in 3 tests.
pearl #10 was heavy. found in 3 tests.
pearl #11 was light. found in 3 tests.
pearl #11 was heavy. found in 3 tests.

if you get to step 2a, you've already used the balance once and you know that the pearl is in 9-12 and therefore 1-8 are all fakes. weighing 1-3 against 9-11 (your second use of the balance) tells you immediately whether it's 12 or one of 9-11 as well as whether it's light or heavy. if you know it's 12 you have to do another weigh (your third) to tell if it's lighter or heavier. if it's one of the other 3, you weigh 9 against 10 (your third). equal means that it's 11 and you know if it's light or heavy from the previous 1-3 vs 9-11 weighing. if you know that it's heavy you take the heavier of the two you just weighed; lighter, you take the lighter of the two.

is that more clear?

actually, i think your version of 2a will run into four weighs. take the case where it's 12. first, you've already weighed 1-4 against 5-8 before you get there. then you weigh 9 against 10 (#2). they're the same so you weigh 9 against 11 (#3). you know that it's 12 but don't have any way of knowing if it's heavy or light so your best bet then would be to guess and be happy with a 50/50 chance of losing your head.

anders pearson


In reply to Re: Re: (GOLF) pearls and perl by thraxil
in thread (GOLF) pearls and perl by thraxil

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.