Re: simple golf for fun
[email protected] (Ton Hospel) Wed, 17 Jan 2007 09:59:37 +0000 (UTC)
| Newsgroups | gmane.comp.lang.perl.golf |
|---|---|
| Organization | lunix confusion services |
| Message-ID | <[email protected]> |
In article <[email protected]>, Phil Carmody <[email protected]> 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.