Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: minimal superstrings/maximal substrings

by tybalt89 (Parson)
on Aug 20, 2019 at 10:45 UTC ( #11104720=note: print w/replies, xml ) Need Help??


in reply to Re: minimal superstrings/maximal substrings
in thread minimal superstrings/maximal substrings

Or use regex to find if there is a word between.

#!/usr/bin/perl # https://perlmonks.org/?node_id=11104709 use strict; use warnings; use List::Util qw( none ); use Path::Tiny; my @words = # get some wor +ds grep /^fun/, # for shorter +testing grep /^[a-z]+$/, path('/usr/share/dict/words')->lines({chomp => 1}); my @longs = grep length $_ >= 9, @words; # all legal lo +ng words my $string = join ' ', sort { length $a <=> length $b } @words; for my $short ( grep length $_ <= 8, @words ) # all legal sh +ort words { for my $long ( grep /$short/, @longs ) # all long sup +erstrings { if( $string !~ # test for wor +d between /\b$short\b.*?\b(\w*$short\w*)\b.*?\b(?=$long\b)\w*\1\w*\b/ ) { print "$long $short\n"; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11104720]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2019-10-18 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?