Not a module, and not OO, but a working solution:
#!perl -l use strict; use warnings; sub sort_word { return join '', sort split //, $_[0]; } my %hints = ( bumps => 2, seams => 2, domes => 3, shake => 3, pokes => 3, dukes => 3 ); my $wordlen = 5; my %dict; open(DICT, '/usr/dict/words') or die "$!: /usr/dict/words\n"; chomp, push @{$dict{sort_word($_)}}, $_ while (<DICT>); close(DICT); my $guess = 'a' x $wordlen; sub letters_in_common { my ($str1, $str2) = @_; my %u = map {$_ => $_} split //, $str1; return scalar(grep defined, delete @u{split //, $str2}); } while (length($guess) == $wordlen) { # Check criteria my $match = 1; while (my ($k,$v) = each %hints) { if (letters_in_common($guess, $k) != $v) { $match = 0; keys %hints; # Reset each last; } } # If match, check dictionary and print results. Done! # Otherwise, increment guess if ($match) { if (exists($dict{$guess})) { print "Solution(s): @{$dict{$guess +}}"; last } else { print "No words match qualifying guess $guess"; } } ++$guess; # Short-circuit: only keep guesses that are sorted # So when the last char flips to an a, flip the trailing # string of last chars to a repetition of the rightmost # non-a $guess =~ s/([^a])(a+)$/$1 x (length($2)+1)/e; }
Update! It works, but I feel pretty stupid for all the work of going through all possible guesses when I should just go through the dictionary keys! Gee, it sure is faster that way!

Caution: Contents may have been coded under pressure.

In reply to Re: Challenge: Mystery Word Puzzle by Roy Johnson
in thread Challenge: Mystery Word Puzzle by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.