15
\$\begingroup\$

Task

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.

Example

input =>
clues:  00100
        00000
        11100
        01210
        22222
or 
        ⬜⬜🟨⬜⬜
        ⬜⬜⬜⬜⬜
        🟨🟨🟨⬜⬜
        ⬜🟨🟩🟨⬜
        🟩🟩🟩🟩🟩
target: CGOLF
words:  ABCDE,CGOLF,EDCBA,LOGOS,VLOGS,WORDS,XYZAB

output =>
ABCDE,XYZAB,LOGOS,VLOGS,CGOLF

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
       11211
       22222
output: DECAB,EDCBA,ABCDE or EDCBA,DECAB,ABCDE

clues: 00100
       22222
output: QWERT,ABCDE

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

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

3 Answers 3

3
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
0
1
\$\begingroup\$

Python3, 195 bytes:

S=set
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!

\$\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.