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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.