[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] longest substring with unique characters




abigail@foad.org wrote:
> 
> my $max = 0; $_ = shift;
> while (/\G(.)(?=((?:(?!\1).)*))/g) {$max = $1.$2 if length $max < length $1.$2}

This fixes the problem Jeff pointed out:

while (/.(?=((??{"[^$&]"})*))/g) {$max = $1 if length $max < length $1}

> print $max, "\n";

I suppose for completeness it should be

    /.(?=((??{"[^\Q$&\E]"})*))/g

but let's just forget that.

Golf:
perl -pe'$_=(sort{length$b<=>length$a}/(?=(.(??{"[^$&]"})*))/g)[0]'

-- 
Rick Delaney
rick.delaney@home.com

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe