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"; } } }
In reply to Re^2: minimal superstrings/maximal substrings
by tybalt89
in thread minimal superstrings/maximal substrings
by stevena
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |