On Thu, Nov 29, 2001 at 03:05:41PM -0500, Michael G Schwern wrote:
On Thu, Nov 29, 2001 at 11:34:24AM -0800, Chris Thorpe wrote:
On Thu, 29 Nov 2001, Yanick wrote:
On Thu, Nov 29, 2001 at 01:34:02PM -0500, Michael G Schwern wrote:
Yesterday, I saw an interesting related
On Mon, Dec 03, 2001 at 12:09:49PM +0100, [EMAIL PROTECTED] wrote:
A Crash Course On BigO Notation As Presented By A Guy Who Failed
Fundamental Data Structures And Algorithms 1 *
O(1) means it runs in a fixed amount of time regardless of how much
data is to be processed.
Greg Bacon [EMAIL PROTECTED] wrote:
You have a finite sequence of unknown length, where each
element in the sequence is a string. Output the middle
element of the sequence (for a reasonable definition of
middle), traversing the sequence at most once and without
storing
Ariel Scolnicov wrote:
*SPOILER*
Here's a solution (that only works for files...)
*SPOILER*
#!/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;
OK, and now flock both handles with LOCK_EX after
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.
On Thu, Nov 29, 2001 at 01:43:27PM -0500, Uri Guttman wrote:
damn, i was thinking about using my module for it. but you have a bug.
Damn, you're right.
a fix is would be to check when the locations in the file are the same
and stop. but File::ReadBackwards doesn't support tell (it does its
MGS == Michael G Schwern [EMAIL PROTECTED] writes:
MGS Tied handles have TELL and SEEK, yep.
well, i could add TELL support easily enough as it knows the location in
the file and where it is in the buffer (just the size of the buffer as
it is going backwards). but i won't add it just to
On Thu, 29 Nov 2001, Yanick wrote:
On Thu, Nov 29, 2001 at 01:34:02PM -0500, Michael G Schwern 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
On Thu, Nov 29, 2001 at 11:34:24AM -0800, Chris Thorpe wrote:
On Thu, 29 Nov 2001, Yanick wrote:
On Thu, Nov 29, 2001 at 01:34:02PM -0500, Michael G Schwern wrote:
Yesterday, I saw an interesting related exercise. Write a program that
reads the lines from a file and outputs the
On 29 Nov 2001, at 11:34, Chris Thorpe wrote:
On Thu, 29 Nov 2001, Yanick wrote:
On Thu, Nov 29, 2001 at 01:34:02PM -0500, Michael G Schwern wrote:
Yesterday, I saw an interesting related exercise. Write a program that
reads the lines from a file and outputs the middle line. The
On Thu, Nov 29, 2001 at 11:34:24AM -0800, Chris Thorpe wrote:
On Thu, 29 Nov 2001, Yanick wrote:
On Thu, Nov 29, 2001 at 01:34:02PM -0500, Michael G Schwern wrote:
Yesterday, I saw an interesting related exercise. Write a program that
reads the lines from a file and outputs the
CT == Chris Thorpe [EMAIL PROTECTED] writes:
CT You can't do it in O(1) memory and O(n) time. There's a time/memory
CT tradeoff. At line m, you have to store m/2 lines in memory if you use
CT O(n) time, if the file stops anywhere between m and m*2 (which you don't
CT know.)
you can
MGS == Michael G Schwern [EMAIL PROTECTED] writes:
MGS A Crash Course On BigO Notation As Presented By A Guy Who Failed
MGS Fundamental Data Structures And Algorithms 1 *
MGS O(1) means it runs in a fixed amount of time regardless of how much
MGS data is to be processed.
Thanks for the crash course on big-o notation.
My comment was merely a response to the discussion about the solution
reading every line 3 times, and its rebuttal that it was really reading
half the lines twice and all the lines once. I should have been more
clear about it.
I was
Yanick wrote:
From the ludicrous department:
perl -p0 -e'1while s/.*?\n(.*\n).+\n?/$1/s;s/\n.*//'
If you want to play golf, I claim a 2-stroke lead:
perl -p0 -e'1while s/.*?\n(.*\n).+\n?/$1/s;s/\n.*//' (Yanick)
perl -p0 -e'$n=y|\n||1;s/(.*\n){$n}//;s/\n.*//s'(Andrew)
Andrew.
On Thu, Nov 29, 2001 at 06:20:37PM -0500, Michael G Schwern wrote:
On Thu, Nov 29, 2001 at 03:40:40PM -0600, Greg Bacon wrote:
Sorry, I wasn't clear on an important point. You only get one pass
through the file.
Does the read from the front and back trick qualify as one or two
passes?
16 matches
Mail list logo