develooper Front page | perl.golf | Postings from January 2007

Re: simple golf for fun

Thread Previous | Thread Next
From:
perl-golf
Date:
January 17, 2007 02:00
Subject:
Re: simple golf for fun
Message ID:
eoks29$bvu$1@post.home.lunix
In article <139073.32692.qm@web25410.mail.ukl.yahoo.com>,
	Phil Carmody <thefatphil@yahoo.co.uk> 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(.*)(.*
)(?=\1.\2|$)//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


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