https://github.com/psaris/wordle demonstrates how wordle is an extension to the mastermind game (https://github.com/psaris/mm).
the README.md describes the mastermind algorithm and how it can be used to solve wordle.
an example demonstrating how the algorithm guesses a random word is demonstrated below:
q)l mm/mm.q
q)l wordle.q
q).mm.score:.mm.veca .wordle.scr
q)C:asc upper read0 `:answers.txt
q)G:asc C,upper read0 `:guesses.txt
q)g:"SOARE"
q)a:.mm.onestep `.mm.maxent
q).mm.summary each .mm.game[a;G;C;g]
rand C n guess score
--------------------
2309 "SOARE" " G G" 28 "GLITZ" " "
8 "HEAVE" " GG G" 1 "PEACE" "GGGGG"
the speed at finding the optimal solution depends critically on the scoring function.
this is my implementation. eager for improvements!
/ redefine the mastermind scoring functions
.mm.scr:{[g;c] g[w:(i:group e_g=c) 1b]:" ";
/ identify and skip where equal
i@:where count[c]>i:g ? c i 0b;
/ identify where misplaced
s:@[" G" e;i except w;:;"Y"]; / generate score s}
sample usage:
q).mm.scr["RIGHT";"RIGHT"] "GGGGG"
q).mm.scr["RIGHT";"WRONG"] "Y Y "
and an example with duplicate letters:
q).mm.scr["RIITE";"RIGHT"] "GG Y "
q).mm.scr["RIGHT";"RIITE"] "GG Y"