There are some fairly dubious coding practices in there, and I don't yet guarentee it solves every puzzle, but it does solve the (now removed) example.
I'll try test it a bit more and clean it up a bit.
#! perl -slw
use strict;
sub uniq { my %x; @x{@_} = (); keys %x }
my $len = shift @ARGV;
my $re = '^';
my $c = 0;
for my $i ( 0 .. $#ARGV ) {
my( $word, $common ) = split ':', $ARGV[ $i ];
die "Bad arg '$ARGV[ $i ]'"
unless $common >= 2 and $common <= length( $word );
my $uniq = join'', uniq( split '', $word );
$re .= "(?=(?:.*?[^$uniq]){${ \ ($len - $common) }})";
$c++;
$re .= "(?=.*?([$word]).*?(?!\\$c)";
$re .= "([$word]).*?(?!"
. join( '|', map{ "\\${ \ $c++ }" } 0 .. $common-2 )
. ')' and --$c
if $common > 2;
$re .= "[$word])";
}
$re .= '.' x $len . '$';
$re = qr[$re];
my %w;
open W, '<', 'words' or die $!;
m[^[a-z]+$] and push @{ $w{ length() } }, $_ while chomp( $_ = <W>||''
+ );
close W;
my @m = grep{ $_ =~ $re } @{ $w{ $len } };
print ~~@m;
print for @m;
__END__
P:\test>421692-1 5 bumps:2 seams:2 domes:3 shake:3 pokes:3 dukes:3
1
house
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|