It seems to me that great efficiencies could be had by applying logical reductions to the rules first. For example, in your given problem, take all the letters for "0 letters" out first:
- The mystery word is 5 letters long
- The mystery word has 2 letters in common with 'hls'
- The mystery word has 3 letters in common with 'olr'
In this case, one rule has reduced to a perfect match. The mystery word must contain 'o','l', and 'r'. I then could subtract those letters from the remaining rules, reducing the counts accordingly. Now the word has one letter in common with 'hs'.
Now I can search for /^[rolh]{5}$/ and /^[rols]{5}$/, finding 'rolls' and 'solos'.
(Update: Of course 'solos' must be eliminated, leaving 'rolls' as the only solution.)
I believe this method could be generalized to a solution-space searching recursive algorithm. I will try to write it up when I have time.
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.