step 2a : weigh 9-11 against 1-3. if they're the same, we know it's 12. weigh 12 against any of the others to determine if it's lighter or heavier then you're done. if 9-11 was heavier than 1-3, you know that the real one is heavy. weigh 9 against 10. if they're equal 11 is the real one. otherwise, the heavier of 9 and 10 is the real one.
step 2a of your algorithm is not correct. tachyon's right. you'll lose your head--there's an extra weighing here. instead, it should go something like this:
step 2a : weigh 9 against 10. if they're the same, we know it's 11 or twelve. then weigh 9 against 11. if they're the same, we know it's twelve; if they're different, it's 11 and you're done. if 9 and 10 are different, weigh 9 against 11. if they're the same, it's 10; if they're different, it's 9 and you're done.
my logic for this bit, which works under strict and warnings, is
$p[8]==$p[9]?$p[8]==$p[10]?12:11:$p[8]==$p[10]?10:9;
or, building the return matrix and putting it in a sub:
do{([9,10],[11,12])[$p[8]==$p[9]]->[$p[8]==$p[10]]}
which is one char shorter.
~Particle ;Þ
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.