develooper Front page | | Postings from January 2007

Re: simple golf for fun

Thread Previous | Thread Next
January 17, 2007 02:00
Re: simple golf for fun
Message ID:
In article <>,
	Phil Carmody <> writes:
> $ echo -e "1\n12\n173\n" | perl -n0 -e 'a//^((.*)(.*
> )(?=\2.\3|$))*$/'
> Illegal division by zero at -e line 1, <> chunk 1.

Yes, it was the expected failure outcome

> Unfortunately it looks like it fails to even finish my 2400-line file - what's
> its Big-Oh? :
> $ time perl -n0 -e 'a//^((.*)(.*
> )(?=\2.\3|$))*$/' < delsieve.log

We are golfers, we don't do efficient :-)

The problem is that regex is not intelligent enough to 
know that once you matches for a line, that's good 
enough for always.

-p0 s/\G(.*)(.*

This should be about as efficient as a simple regex
approach gets. It's also the shortest yet :-)
It outputs starting from the first line that can't
be extended. No output means all lines work.

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