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

Re: [FWP] longest substring with unique characters




For some reason, I'm finding the brute force approach rather appealing:

  sub longest($) {
    my $w = shift;
    for my $len ( reverse 1 .. length($w) ) {
      for my $ofs ( 0 .. length($w)-$len ) {
        my $s = substr( $w, $ofs, $len );
        $s =~ /(.).*\1/ or return $s;
      }
    }
  }


-- 
John Porter

Took away his vocal, put him in a blackhole,
 blocking up the entrance with tar and muck


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