in reply to Re: Finding largest common subset in lists?
in thread Finding largest common subset in lists?

So close! It works almost all the time, but this test case fails:
my @a = qw( a b c d e f g h i j k l m n o p q r s t u v w x y z ); my @b = qw( a b c X f g h X l m n X j k a b c d );
Running on this, I get a b c as the result instead of a b c d. I'm looking to see if I can figure out why now, but I figured I'd post in case someone's faster than me (likely).

Replies are listed 'Best First'.
Re: Re: Re: Finding largest common subset in lists?
by Jenda (Abbot) on Jun 06, 2003 at 09:32 UTC

    I'm stupid, stupid, stupid. There should be:

    .... if ($end > @result) { @result = @a[0..$end-1]; } ...
    instead of
    ... if (--$end > @result) { @result = @a[0..$end]; } ...
    The way I have it I'd only update the @result if the newly found list was longer by at least 2 items. The usual off-by-one error :-(

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature