develooper Front page | perl.golf | Postings from July 2002

Re: My solution annotated

Thread Previous | Thread Next
From:
Julien Quint
Date:
July 8, 2002 08:14
Subject:
Re: My solution annotated
Message ID:
20020708151306.GA6715@houdini.imag.fr
On Mon, Jul 08, 2002 at 10:54:15AM -0400, Ala Qumsieh wrote:
> s/^(.*) \1$/$1/mg;

By writing s/^(.*) \1$/$1/m|... I could get rid of the g (gaining one stroke)
by piggybacking on the while loop to remove all the duplicates. A slight
disadvantage is that the runtime is considerably longer -- the large test cases
take a few seconds to complete -- but it stays in the "reasonable" frame.

> $_&&&

This is good. I struggled for quite some time with a $_&&die statement at the
end (the funkiest way to write it that I found was ??&&die, but still it was
too long) when I thought of the divide-by-zero trick that many players used,
hence:

  1/!$_

which is exactly the same length (but I've seen a/!//, which i like better)
and dies when the input string is not-empty (hence !$_ is equal to zero) as
it tries to divide by zero. Otherwise, my solution is the same as Ala's.

pom

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About