On Thu, Nov 29, 2001 at 01:34:02PM -0500, Michael G Schwern wrote:
> On Thu, Nov 29, 2001 at 03:17:39PM +0200, Ariel Scolnicov wrote:
> > > Yesterday, I saw an interesting related exercise. Write a program that
> > > reads the lines from a file and outputs the middle line. The kicker is
> > > that you can't use arrays.
>
> I'll interpret that as O(1) memory, O(n) time.
>
> > #!/usr/local/bin/perl -w
> > # Print middle line of file(s)
> > use strict;
> > open F,$ARGV[0] or die;
> > open G,$ARGV[0] or die;
> > my $l;
> > 1 while (defined(<F>) && defined($l=<G>) && defined(<F>));
> > print $l;
>
> That requires reading each line three times.
Uh. No? Half of the lines are read twice, and the rest is
only read once...
Joy,
`/anick
--
print map chr int ($_/1.1), map ord, split '',
'bp�$kz{�sp~$Yp~w$skmvp~3';