Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Challenge: Mystery Word Puzzle

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


in reply to Re^2: Challenge: Mystery Word Puzzle
in thread Challenge: Mystery Word Puzzle

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://422114]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found