Don't Wordle: an optimiser


The optimiser runs a client-side bounded beam search over legal Don't Wordle trajectories, parameterised by a known target word. The search space is the set of six-word sequences drawn from the 12,972 valid Wordle guess words, with the additional constraint that the target word itself is never guessed.

Each candidate guess is precompiled against the target into a compact constraint object. This contains the Wordle feedback vector over {green, yellow, grey}, a bitmask of the unique letters used, fixed-position green constraints, per-position yellow exclusions, per-letter lower bounds from green and yellow multiplicity, and per-letter upper bounds induced by grey duplicate tiles.

For example, if the target is FABLE and the guess is AYAYA, the feedback is yellow-grey-grey-grey-grey. This implies a lower bound of one A and an upper bound of one A. Later guesses may therefore contain exactly one A, not zero and not two or more.

A sequence is legal only if every later guess satisfies every constraint implied by every earlier row. Greens fix absolute positions. Yellows require the letter to recur while excluding the original position. Greys impose upper bounds: a fully grey letter has maximum count zero, while a grey copy of a duplicated letter caps the count at the number of non-grey copies seen in that row.

The optimiser searches backwards. A partial state is a legal suffix of the final six guesses. To prepend a candidate guess, the algorithm checks whether all words already in the suffix satisfy the constraints created by that candidate's feedback. If not, the candidate cannot have appeared earlier and the branch is discarded.

This is useful because an early guess constrains all later guesses. Working backwards allows the optimiser to reject incompatible prefixes before they are expanded into full six-row trajectories.

Exhaustive enumeration of the complete legal tree is usually too expensive for an interactive browser page. Instead, the optimiser uses beam search. After each expansion step it ranks partial suffixes with a heuristic and retains only the best N states, where N is the value in the Search effort box.

The heuristic combines both terms in the final objective: it strongly prefers states that conserve alphabet letters, while also favouring states that leave a larger current set of possible remaining words.

Search effort is therefore a beam width, not a depth parameter. Increasing it explores more of the search tree and may improve the returned sequence, but it increases runtime. Because branches outside the beam are discarded, the browser version reports the best sequence found within the selected beam rather than a proof of global optimality.

Complete six-guess paths are scored exactly. The score is:

|alphabet \ used_letters(path)| x |{w in W : w satisfies all six feedback rows}|

Here W is the 12,972-word valid-guess set. The first factor rewards conserving alphabet letters across the six guesses. The second factor rewards preserving ambiguity: it counts how many words remain consistent with the accumulated constraint system after row 6. Computationally, the task is a constrained combinatorial optimisation problem over W^6, approximated here by reverse beam search with exact evaluation of retained terminal states.