[EMAIL PROTECTED] schreef op 30 november 2001:
> Yannick's last solution:
> 
> perl -p0 -e'$_=$1while/\n(.*)\n/s'      (Yv3.2)
> 
> prints two centre lines when presented with a
> test file containing an odd number of lines.

This can be repaired at the cost of one stroke:

  perl -p0 -e'$_=$1while/\n(.*)\n./s'

This prints the two centre lines for files of even length, which is
more reasonable.

> I think this leaves the current golf leader as
> Eugene on 37 strokes (35 under par) with:
> 
> perl -p0 -e'$_=(/(.*\n)/g)[y|\n||/2]'
> 
> Eugene, I like this solution (and I think we should
> have an 'open' category in any case), but there
> may be a protest if someone suggests this solution
> violates the 'no array' requirement.

It's a list! Not an array!

But you're right, both solutions are O(n) in memory.
The shortest O(1) solution I've found is a variant of Ian Phillipps'
solution:

perl -e'open$_,$ARGV[0]for F,G;<G>while<F>,<F>;die$_=<G>'


Eugene

Reply via email to