10

A clever puzzle in the Sunday New York Times Magazine is CROSS TIES (by Will Shortz). You are given a $5 \times 5$ grid with some squares filled with letters, others grayed out, and yet others white. The puzzle is to fill in the remaining white squares with letters so as to spell valid English words or names that all are examples from the same category or class.

One puzzle is shown on the left, and its solution (with red letters) is at the right:

CROSS TIES PUZZLE AND SOLUTION

It is a fairly straightforward Mathematica search to find all dictionary words that fit the constraints of a given word, for example:

DictionaryLookup["w"~~_~~"is"~~_]

and

DictionaryLookup[_~~"o"~~_]

for two of them here.

I'm seeking an elegant method to impose all the constraints (by defining variable-letter names) so that the routine returns only the final solution words. (You can hand-code the problem-specific data for each such puzzle.)

The ideal case would be to also demand all solution words be semantically related... to enforce the semantic constraint of the problem. (Frankly, I suspect that most puzzles are so constrained that only the intended solution words will fit, but in some cases others might fit as well.)

Test your solution out on this:

CROSS TIES PROBLEM

Another:

enter image description here

Another:

enter image description here


Here's a first pass at a solution, admittedly a bit ugly and efficient, and not in a Mathematica style.

Consider a simple but relevant example:

sample problem

Then something like:

solutions = {};
words = {DictionaryLookup["w" ~~ _ ~~ _ ~~ _],
   DictionaryLookup[_ ~~ _ ~~ "o"],
   DictionaryLookup[_ ~~ _ ~~ "g"]};

Table[
  If[(StringTake[words[[1, i]], {2}] == 
     StringTake[words[[2, j]], {2}]) && 
    (StringTake[words[[1, i]], {4}] == 
     StringTake[words[[3, k]], {1}]), 
   AppendTo[solutions, {words[[1, i]], words[[2, j]], words[[3, k]]}]],
  {i, Length[words[[1]]]},
  {j, Length[words[[2]]]},
  {k, Length[words[[3]]]}
  ];

solutions

Surely there is a more elegant way to perform this...

David G. Stork
  • 41,180
  • 3
  • 34
  • 96
  • Can you share the code which you used to generate the example/test case? – CA Trevillian Mar 25 '20 at 04:54
  • 1
    @CATrevillian: My code did not generate the problems... I just copied the problems in today's magazine. – David G. Stork Mar 25 '20 at 05:03
  • Ah, my mistake! The last one you include appeared different than the previous, leading to my inquiry. Thank you for this fun puzzle (to solve a puzzle!). Are they only in the magazine? I can’t seem to find a decent resource to see them online. – CA Trevillian Mar 25 '20 at 05:10
  • Note that solutions aren't guaranteed to be unique, e.g. $$\text{WAIST}\ \text{■D■■O}\ \text{■UNTO}\ \text{■L■■■}\ \text{ITCH■}$$ – J. M.'s missing motivation Mar 25 '20 at 05:13
  • J.M.'stechnicaldifficulties... This is a (partial) solution... That's why the full problem constrained the words to be about the same general topic. A sophisticated code would (somehow) include semantic cohesion. But did you solve that by hand? – David G. Stork Mar 25 '20 at 06:01
  • I think word vectors are the solution here. You want to constrain your results to words that are only a certain distance from one another. There are a lot of word vectors generated by neural networks here or there is a built in "WordVectors" classifier. – Carl Lange Mar 25 '20 at 08:53
  • Excellent idea. How to implement it? – David G. Stork Mar 25 '20 at 12:25
  • 1
    There's probably a lot to learn from https://mathematica.stackexchange.com/questions/5387/how-can-i-use-mathematicas-graph-functions-to-cheat-at-boggle/5392. I'm supposed to be working from home right now, but will pick this up again later. – High Performance Mark Mar 25 '20 at 13:20
  • 1
    @DavidG.Stork are the words supposed to be nouns only? – Vitaliy Kaurov Mar 26 '20 at 01:22
  • No... I don't think they need be nouns only. I do suspect, though, that within one puzzle they should all be nouns, or all verbs, or all adjectives, or all names... – David G. Stork Mar 26 '20 at 01:53
  • For those who want to try further: 2nd: {{"mango"}, {"apple"}, {"pear"}, {"grape"}} 3rd: {{"harp"}, {"piano"}, {"organ"}, {"oboe"}} – Syed Oct 22 '23 at 17:57

0 Answers0