I ignored assumption #2, but the results of the following code do not violate that assumption (for this example anyway). I get two possible groups of five letters, for the sake of time, I'm not scanning any dictionary for these combinations. Even though it's probably easier to brute force a dictionary, I went the "let's find valid letter groups" route :)
use strict;
use warnings;
my $word = "aaaaa";
my @words;
{
push @words, $word
if
$word =~ tr/bumps// == 2 and
$word =~ tr/seam// == 2 and
$word =~ tr/domes// == 3 and
$word =~ tr/shake// == 3 and
$word =~ tr/pokes// == 3 and
$word =~ tr/dukes// == 3;
last if $word eq "zzzzz";
$word = inc_letter($word, 4);
redo;
}
print "$_\n" for @words;
sub inc_letter {
my ($word, $i) = @_;
if (substr($word, $i, 1) eq "z") {
$word = inc_letter($word, $i-1, 1);
substr($word, $i, 1) = substr($word, $i-1, 1);
} else {
substr($word, $i, 1)++;
}
$word;
}
Update: The puzzle changed; this solution has not. If a general solution is desired, then more work would need to be done here.
-
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.