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

Re: [FWP] longest substring with unique characters



On Jan 18 around 11:18pm, Casey R. Tweten hammered out this masterpiece:

: Dan Chetlin brought up this challenge on #perl and I accepted.
: 
: This is my first round so it's a little long and no doubt slow:

And it has some errors.  Here's my second shot:

foreach my $line ( @lines ) {
  my $long  = '';         
  $long = ( sort { length $a <=> length $b } map {
    length( $_ = substr $line, $-[0], $_ + 1 ) > length $long
    && ! /(.).*(\1)/ ? $_ : $long;
  } $-[0] .. length $line )[-1] while $line =~ /./g;    
  print "$long\n";
}
 
__DATA__
that
abcdefa
abcdabc
testing
this test
abcdefg  
a


-- 
print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'crt@kiski.net',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>


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