Given a winning Wordle play results (clues), the target ("secret") word and a list of words, output a possible sequence of words leading to such results.

The words in the list will be distinct and so should be the output.

You may assume that for given inputs a solution exists. If there is more than one, you may output any or all of them.

Take your input in any convenient manner: including string of coloured rectangles, string of 3 distinct characters of your choice, array of 3 distinct values, etc. You may output list of words first-to-last or reversed.

You can omit the last row of clues as it will be all "green" or take the target word as the last row if you like. The target word is also optional in the output.

This is , so shortest answer wins.


input =>
clues:  00100
target: CGOLF

output =>

How does Wordle exactly work?

Taken from @pxeger's related challenge.

In Wordle, you try to guess a secret 5-letter word, and some letters in your guess are highlighted to give you hints.

If you guess a letter which matches the letter in the same position in the secret word, the letter will be highlighted green. For example, if the secret word is LEMON and you guess BEACH, then the E will be highlighted green.

If you guess a letter which is present in the secret word, but not in the correct corresponding position, it will be highlighted yellow.

If a letter appears more times in the guess than it does in the secret word, only upto as many occur in the secret may be highlighted. If any of the occurrences are in the same place, they should be preferentially highlighted green, leaving earlier letters unhighlighted if necessary.

For example, with the secret LEMON and the guess SCOOP, the second O will be green, because it is in the right place, but the first O will be unhighlighted, because there is only one O in the secret, and one O has already been highlighted.

Any of the remaining letters in the secret may be highlighted yellow if they match, as long as the right number are highlighted in total. For example, with the secret LEMON and the guess GOOSE, only one of the Os should be highlighted; it does not matter which.

Test cases

Use ABCDE as target and ABCDE,DECAB,EDCBA,QWERT as words:

clues: 22222
output: ABCDE

clues: 11211

clues: 00100

Use GOOSE as target and GOOSE,LEMON,SCOOP as words:

clues: 01010
  • \$\begingroup\$ Can we output the same word multiple times? \$\endgroup\$
    – ophact
    Mar 8, 2022 at 8:34
  • \$\begingroup\$ @orphact no, I'll clarify. \$\endgroup\$
    – pajonk
    Mar 8, 2022 at 8:35

3 Answers 3


Python 3, 155 bytes

Based on my submission for the related challenge, uses the same color encoding: -1 for Green, 0 for Yellow and 1 for not highlighted.

def f(g,s,w):
 for l in g:k=[k for k in w if(c:='')or[-(a==b)or(c:=c+b).count(b)>sum(y!=x==b for x,y in zip(s,k))for a,b in zip(s,k)]==l][0];yield k;w-={k}

Try it online!


Python 3, 164 bytes

f=lambda a,b,c:a and[[w]+f(a[1:],b,c-{w})for w in c for t in[[*b]]if[not a or a in t and t.remove(a)for a in[a[a==b:]or t.remove(a)for a,b in[*zip(w,t)]]]==a[0]][0]

Try it online!

Based on my answer to Highlight a Wordle guess


Python3, 195 bytes:

f=lambda b,t,w,p=[]:f(b[1:],t,w,p+[i for i in S(w)-S(p)if sum(j==k for j,k in zip(i,t))==(J:=(F:=b[0].count)(2))and(sum(l in t for l in i)-J==F(1)or len(S(i)&S(t))-J==F(1))][:1])if b else p

Try it online!


Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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