On Sun, Dec 02, 2001 at 08:14:00AM -0500, Bernie Cosell wrote:
> Would someone take a step back from the Perl intricacies and tell me if 
> they even have an *algorithm* [much less a Perl program] that meets the 
> problem's criteria.  I as got it:
>    1) you can only read the file once, from beginning to end [no 
> 'seek'ing around or other hackery -- assume the file is a TCP stream or a 
> pipe]
>    2) you can only use O(1) storage
>    3) you must print out the 'middle' line of the file.

The second constraint was not "use 0(1) storage", but "don't use arrays".
Greg, who posted the initial challenge, solved this with recursion.

The trouble is that "don't use arrays" is an arbitrary constraint, so there
are arbitrary ways to avoid it, such as storing the entire file in a
string, using recursion and storing the entire file in the call stack, etc.


> My intuition is that the problem is too constrained and that there 
> *is*no* algorithm that meets all the criteria, but I'd be delighted to be 
> proven wrong...

You're right.  The challenge as you stated it is too constrained, and there
is no solution.  The challenge as Greg stated it is too vague, and there
are several trivial solutions.

Ronald

Reply via email to