On Apr 13, 2002 at 11:45:33 +0000, Ton Hospel wrote:
> 
> The really interesting entry is in fact the one by Rick Myers 
> because it can be trivially improved to 54:
> 
> -l for$.(++$_..pop){s!.!$.*"$&.$'"%($`?10:$^T)!eg}print

Hmm.. Well, the ++$_ would've been good for 60, but the twist
of moving $& inside the double quotes breaks for me with
input values >= 45.

The problem is that as $& grows in length, it pushes the
trailing digits of $' past were perl will "see" them when it
converts the value to float (for the *). The conversion back
to int (by the %) then causes an off-by-one type rounding
error.

In other words, at 45, for the last non-zero digit...

    $.*$&+$.*".$'" == 126

    $.*"$&.$'" == 125.9999999999999857891452847979962825775146484375

The confounding part about it though was that using just 7
digits of lookahead...

-l for$.(++$_..pop){s!.(?=(.{0,7}))!($.*$&+$.*".$1")%($`?10:$^T)!eg}print

.... works fine, even though I've intentionally lopped off
most of the least significant digits. A similar trick with
"$&.$1" here breaks again at 45. Grrr!

--rick

Reply via email to