5
\$\begingroup\$

This challenge is a sequel to Letter Boxed Validator.

The New York Times has a daily online game called Letter Boxed (the link is behind a paywall; the game is also described here), presented on a square as follows:

Letter Boxed example from the New York Times

You are given 4 groups of 3 letters (each group corresponds to one side on the picture); no letter appears twice. The aim of the game is to find words made of those 12 letters (and those letters only) such that:

  • Each word is at least 3 letters long;
  • Consecutive letters cannot be from the same side;
  • The last letter of a word becomes the first letter of the next word;
  • All letters are used at least once (letters can be reused).

In this challenge, you are given the letters, and a dictionary. The goal is to output a valid solution, which minimizes the number of words used. If there is no solution, any consistent output is acceptable.

For the input {{I,C,O}, {M,R,E}, {G,N,S}, {A,P,L}}, a valid solution is PILGRIMAGE, ENCLOSE. Another valid solution is SOMNOLENCE, EPIGRAM. The following are not valid:

  • PILGRIMAGE, ECONOMIES (can't have CO since they are on the same side)
  • GRIMACES, SOPRANO (L has not been used)
  • PILGRIMAGE, ENCLOSURE (U is not one of the 12 letters)
  • ENCLOSE, PILGRIMAGE (last letter of 1st word is not first letter of 2nd word)
  • CROPS, SAIL, LEAN, NOPE, ENIGMA (number of words is not minimal)

Input

Input consists of a dictionary, and of 4 groups of 3 letters. It can be in any suitable format.

Output

A list of words giving a solution to the challenge. There may be several acceptable solutions: you should output at least one, but may output several if you want.

Test cases

The test cases use this dictionary. If using a large dictionary is too difficult on TIO, you may use instead the dictionary {PILGRIMAGE, ENCLOSE, SOMNOLENCE, EPIGRAM, ECONOMIES, GRIMACES, SOPRANO, ENCLOSURE, CROPS, SAIL, LEAN, NOPE, ENIGMA, OVERFLOWS, STACK, QUESTIONABLY, QUARTZ, ZIGZAG, GHERKIN, CODE, GOLF, NO, I, DO, NOT, IN}, but your code should in principle work on a larger dictionary.

Note that the solution is not necessarily unique; these are possible solutions.

Input={{I,C,O}, {M,R,E}, {G,N,S}, {A,P,L}}. Solution: PILGRIMAGE, ENCLOSE

Input:{{OSA}, {FVK}, {WEL}, {CTR}}. Solution: OVERFLOWS, STACK.

Input: {{BCD}, {FGH}, {JKL}, {MNP}}. No solution.

Input: {{AQT}, {LUI}, {BOE}, {NSY}}. Solution: QUESTIONABLY

Input: {{QGN}, {ZUR}, {AHK}, {ITE}}. Solution: QUARTZ, ZIGZAG, GHERKIN.

Scoring:

This , lowest score in bytes wins!

\$\endgroup\$
  • \$\begingroup\$ Sandbox link \$\endgroup\$ – Robin Ryder Jun 23 at 11:02
  • \$\begingroup\$ Do I receive the dictionary as input? \$\endgroup\$ – Embodiment of Ignorance Jun 23 at 11:07
  • \$\begingroup\$ @EmbodimentofIgnorance Yes, dictionary is part of the input. Clarified. \$\endgroup\$ – Robin Ryder Jun 23 at 11:09
  • 1
    \$\begingroup\$ Such a large dictionary is going to be hard to embed in TIO links -- if it's possible at all. I'd recommend to provide a much smaller dictionary including all words used in the solutions and just a couple of other useless ones. \$\endgroup\$ – Arnauld Jun 23 at 11:25
  • 1
    \$\begingroup\$ @Arnauld OK, I've added a small dictionary which should be enough for all test cases. \$\endgroup\$ – Robin Ryder Jun 23 at 11:35
1
\$\begingroup\$

Jelly, 38 bytes

iⱮⱮL>2ƊƇẠƇ’:3IẠƲƇŒPU=ḢɗƝẠ$ƇFQL=ʋƇ12ịḷḢ

Try it online!

A dyadic link taking the flattened letters as left argument and the dictionary as right. Returns a list of strings of one of the shortest solutions, or a zero if there is no solution.

Full explanation to follow once it’s a bit better golfed.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.