in reply to (GOLF) pearls and perl
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 ;Þ
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: (GOLF) pearls and perl
by thraxil (Prior) on Apr 04, 2002 at 15:39 UTC | |
by particle (Vicar) on Apr 13, 2002 at 15:00 UTC |