Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Challenge: Mystery Word Puzzle

by Solo (Deacon)
on Jan 12, 2005 at 22:15 UTC ( [id://421802]=note: print w/replies, xml ) Need Help??


in reply to Challenge: Mystery Word Puzzle

I have the start of an idea that the puzzle can be looked at as linear system simlutaneous equations where the hint words are each an equation and the length of the word is another.

For the 'house' example, we'd get the system:

   e k ops = 3
a  e  m  s = 2
  de  mo s = 3
a  ehk   s = 3
  de k   su= 3
 b    m psu= 2
abdehkmopsu <= 5

Where each of the variables (a,b,d,e,...,u) can be 0 or 1. IF there is/are solution(s) to this system, we're done. The word(s) must contain only those letters--a very simple anagram search.

If there isn't an exact solution, the system can be reduced, reducing the rules set for the dictionary search.

Update: Given the OP's additional rule:

There will be no letters in the mystery word that are not covered by the hint words. Added 2005-01-12 16:10:00 EST

I'm more convinced this approach is sound, but I won't get to coding anything until the weekend.

--Solo

--
You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

Replies are listed 'Best First'.
Re^2: Challenge: Mystery Word Puzzle
by dragonchild (Archbishop) on Jan 13, 2005 at 04:27 UTC
    Where each of the variables (a,b,d,e,...,u) can be 0 or 1.

    Therein lies the problem. What if the answer was "shoes" ... you now have 2 S'es ... that's why this cannot really be solved algebraically. Now, if the requirement was that you didn't take unique letters but instead followed the rules of Jotto, then simultaneous equations would work just fine.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Per the OP:
      The number of letters in common is the exact number of unique letters in common. A 't' would only be counted once even if it existed twice in both the mystery word and the hint word

      Update:That is why the final equation is LESS THAN or equal to. The letters may appear more than once, reducing the total number of unique letters, but no more than the number of letters in the secret word can be used.

      --Solo

      --
      You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.
Re^2: Challenge: Mystery Word Puzzle
by CountZero (Bishop) on Jan 13, 2005 at 20:13 UTC
    I vaguely seem to remember from math lessons long long ago, that to guarantee a unique solution, you must have at least as many "mutually independent" equations (the right mathematical name escapes me, what I mean is equations which cannot be simply transformed into each other; eg: 'A = 2' and '2 * A = 4' are not mutually independent) as there are variables.

    So for a system with 11 variables, 5 hints plus the mystery word do not guarantee you a unique solution, which seems to tally with the results reported. Of course the requirement that the word must exist, may make the solution unique but that is beyond mathematics!

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      I would argue that the goal behind the mathematics (and you have your rules down, if not the terminology) is to come up with a set of "words" that satisfy the hints. This narrows the searchspace down dramatically. Then, it's a matter of a simple anagram-matching program (which is a lot quicker than the programs that were discussed here) to find the correct word(s).

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      So for a system with 11 variables, 5 hints plus the mystery word do not guarantee you a unique solution

      Agreed, but I'm not sure my analogy carries through that far. But I'm more confident the algorithm will work now that all letters in the word must be covered by the hints.

      Let me try to expand on my thinking. Given the equations:

      e + k + o + p + s = 3 a + e + m + s = 2 d + e + m + o + s = 3 a + e + h + k + s = 3 d + e + k + s + u = 3 b + m + p + s + u = 2 a + b + d + e + h + k + m + o + p + s + u <= 5
      As a worst case, we can use brute-force substitution to find all solution sets--i.e. try (a=1,b=0,...), try (a=1,b=1,d=0,...), ... tye would quickly apply Algorithm-Loops's NestedLoops and have the solution sets.

      Now we have 'categorical' solutions, but we don't know if any of these categories contain dictionary words.

      We could use the categories as the regexes to search the dictionary with, for example if the solution categories were 'adet' and 'adev' for a 5-letter word:

      /^[adet]{5}$/ || /^[adev]{5}$/

      Yuk, because if there are many regexes, I want my code to optimize how it writes the regexes, and I know I'm not smart enough to do that correctly. I'm barely smart enough to see that doesn't work by itself :P

      So, I would prepare the dictionary according to the same categories the solutions represent (i.e. hash it with the categories). Then I can look up whether there are solution words very quickly. For example:

      'adet' => [ 'date', 'dated', ... ], 'adev' => [ 'dave', 'evade', 'evaded', ... ],

      Any words in the hash category with the correct number of letters is a solution.

      If I persist this dictionary hash, I need only create it once (for each dictionary.)

      Update: The dictionary hashing idea is used by other monks (as perhaps the whole algorithm is, sorry I haven't looked closely at anyone else's code.)

      --Solo

      --
      You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://421802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-23 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found