Re: In place sorting

2001-07-26 Thread Andrew Pimlott
On Thu, Jul 26, 2001 at 03:06:38AM -0700, Abigail wrote: > We all remember our fundamental algorithms, don't we? Not really, which is why it's good to have you remind us :-) Now that you mention it, though, > sub heapify () { > my ($code, $index, $array, $bound) = @_; > { > m

Re: In place sorting

2001-07-27 Thread Andrew Pimlott
On Fri, Jul 27, 2001 at 08:38:13AM +0200, Abigail wrote: > On Fri, Jul 27, 2001 at 12:13:45AM -0400, Andrew Pimlott wrote: > > (The original works, by chance.) > > Nah, not by chance. It works fine. It's just that the top element of > the heap only has one child - but that

Re: Sorting in-place

2001-08-06 Thread Andrew Pimlott
On Tue, Aug 07, 2001 at 12:27:50AM +0300, Ilmari Karonen wrote: > () is an empty list, and the fact that an empty list > constant evaluates to undef in *scalar* context is an explicit feature > of constant.pm. It doesn't. "()" isn't an empty list in scalar context. "A list in scalar context" is

Re: evaluating assigning to a list in if( ) statement

2001-09-10 Thread Andrew Pimlott
On Tue, Sep 04, 2001 at 08:52:11AM -0400, Jeff 'japhy/Marillion' Pinyan wrote: > And the difference is? An array isn't the same as a list, but assigning > to an array is the same as assigning to a list. Consider the difference between @a = (1, 2); and ($a[0], $a[1], $a[2]) = (1, 2) A

Re: Longest Common Substring

2002-02-14 Thread Andrew Pimlott
On Thu, Feb 14, 2002 at 10:20:50PM -0500, Jeff 'japhy' Pinyan wrote: > while ($str =~ m{ ([^\0]{$len,}) (?= [^\0]* \0 [^\0]*? \1 ) }xg) { Thanks to the comma, ^ > $len = length($match = $1) + 1; > } this is O(N^3) in the case of no common substring: - 1 factor for the posit

Re: Longest Common Substring

2002-02-14 Thread Andrew Pimlott
On Fri, Feb 15, 2002 at 01:37:15AM -0500, Jeff 'japhy' Pinyan wrote: > Except that you are forced to find a 2-character match, which means you > end up skipping a POTENTIAL 3-character-or-more match. Due to the while loop, we will keep looking for longer matches. Otherwise, your version would hav

Re: Longest Common Substring

2002-02-15 Thread Andrew Pimlott
On Fri, Feb 15, 2002 at 07:27:03AM -0600, Tim Ayers wrote: > No offense, but did you try it without the comma? Gosh, now we're getting picky! This is "fun with perl", not "working code with perl"! > It doesn't work. If > you get a 2-character match, the regex engine gains a new starting > point

Re: rethinking printf

2002-03-06 Thread Andrew Pimlott
On Wed, Mar 06, 2002 at 09:45:18AM -0800, Rich Morin wrote: > Going a bit further afield, I also started thinking about the general > nature of printf. I've been using this basic syntax since 1970 (in > the form of Fortran's FORMAT statements :-), so I'm pretty comfortable > with it. OTOH, I don

Re: Sort is lazy?!? (as in Haskell)

2002-03-10 Thread Andrew Pimlott
On Sun, Mar 10, 2002 at 10:16:05PM +, Jonathan E. Paton wrote: > A lazy sort can be done in n time, easily: > > @highest; > foreach element { >if (element > lowest in @highest) { ^^ You haven't kept @highest sorted, so there is another factor of n. >

Re: Sort is lazy?!? (as in Haskell)

2002-03-10 Thread Andrew Pimlott
On Sun, Mar 10, 2002 at 11:11:00PM +, Jonathan E. Paton wrote: > > > A lazy sort can be done in n time, easily: > > > > > > @highest; > > > foreach element { > > >if (element > lowest in @highest) { > >^^ > > You haven't kept @highest sorted, so there i

Re: Fisher-Yates shuffle

2002-04-04 Thread Andrew Pimlott
On Wed, Apr 03, 2002 at 10:37:08PM -0700, Sean M. Burke wrote: > sub fy2 { >my($deck,$i,$j,$t) = $_[0]; >$i = @$deck || return; >while(1) { > $j = int rand($i-- || return); This causes a useless iteration when $i == 1. I'm guessing you know this, but it still helped your benchma

Re: Fisher-Yates shuffle

2002-04-05 Thread Andrew Pimlott
On Thu, Apr 04, 2002 at 06:12:18PM -0600, [EMAIL PROTECTED] wrote: > It it a requirement of the Fisher-Yates shuffle that the "randomizing > window" grow smaller through each iteration? Why not just do: > > sub shuffle { > my $deck = shift; > my $size = @$deck; > my ($j, $t); > for (@$dec

Re: Fisher-Yates shuffle

2002-04-13 Thread Andrew Pimlott
On Sat, Apr 13, 2002 at 12:51:06AM -0700, Ashley Winters wrote: > Perl today: A semicolon is required after every statement, except before a > closing curly or end of file. > Perl 6: A semicolon is also required after every block, except when the > closing curly is on a line of its own, or it prec

Re: regexp apocalypse

2002-06-05 Thread Andrew Pimlott
On Wed, Jun 05, 2002 at 01:03:39PM +0100, Stephen Turner wrote: > is _much_ worse for golf than (?=PATTERN) ! Larry has obvious lost touch with his constituency. :-) Andrew

Re: Hidden state? Invisible closures?

2003-05-27 Thread Andrew Pimlott
On Tue, May 27, 2003 at 05:27:00PM +0100, Simon Cozens wrote: > I'd say it was undefined behaviour. Modification of a read-only value attempted? Andrew

TRUE

2004-01-21 Thread Andrew Pimlott
I like to use symbolic constants. Wha can remember what all those 1, 0, undef, and ''s mean anyway? So I start off all my programs with use constant FALSE => !TRUE; use constant TRUE => !FALSE; Andrew

Re: TRUE

2004-01-21 Thread Andrew Pimlott
On Wed, Jan 21, 2004 at 06:43:26PM +0200, Gaal Yahas wrote: > On Wed, Jan 21, 2004 at 11:09:29AM -0500, Andrew Pimlott wrote: > > use constant FALSE => !TRUE; > > use constant TRUE => !FALSE; > > I start off all my programs with use strict :-) Wimp. :-) >

Re: Unknown level of hash

2005-03-28 Thread Andrew Pimlott
On Mon, Mar 28, 2005 at 03:06:41PM -0800, Zhuang Li wrote: > Hi, given an array: @a = ('E1', 'E2', ..., 'En'); > > Is there an easy way, hopefully one liner, to do the following without a > loop? If not, will Perl support this in Perl 6? > > $hash->{E1}->{E2}->...->{En} = 1; If you're feeling f

Re: Unknown level of hash

2005-03-29 Thread Andrew Pimlott
On Tue, Mar 29, 2005 at 11:30:49AM +0200, Alexandre Jousset wrote: > Andrew Pimlott wrote: > > > If you're feeling functional, > > > > ${fold_left(sub { \${$_[0]}->{$_[1]} }, \$hash, @a)} = 1; > > > > To get the value back out: > > > >

Re: Unknown level of hash

2005-03-29 Thread Andrew Pimlott
On Tue, Mar 29, 2005 at 06:42:41PM +0200, Alexandre Jousset wrote: > Alexandre Jousset wrote: > >Andrew Pimlott wrote: > > > >>>>(You should be able to write the first one as > >>>> > >>>> ${fold_left { \${$_[0]}->{$_[1]} } \$has