develooper Front page | | Postings from July 2002

Re: My solution annotated

Thread Previous | Thread Next
Julien Quint
July 8, 2002 08:14
Re: My solution annotated
Message ID:
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,


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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About