A Clojure library designed to generate and solve wordle-style puzzles.
This works reasonably well. It doesn't have a client interface to the real Wordle server; that coulf be done but it wasn't my objective.
It solves 94% of wordles in random tests in 6 or fewer attempts; the distribution of attempts in testing is:
wordleist.core=> (frequencies (map :attempts s))
{1 1,
2 37,
3 30,
nil 6, ;; these are the failures
4 18,
5 6,
6 2}
Core functions
(wordle target guess)
: given thistarget
as the word sought, return the wordle pattern for thisguess
.(wordle-gen)
: return a new wordle function, whose target is a word chosen at random from the word list.(consistent? pattern target)
: Wherepattern
is a pattern as returned bywordle
, andtarget
is a string representing a five letter word, returntrue
ittarget
is consistent withpattern
, else false.(solve game)
: Solves a wordle game, and returns the solution.
Example:
wordleist.core=> (pprint (solve (wordle-gen)))
{:word "young",
:attempts 5,
:patterns
(([:not-present \s]
[:not-present \e]
[:not-present \a]
[:present \o]
[:not-present \r])
([:not-present \w]
[:found \o]
[:found \u]
[:not-present \l]
[:not-present \d])
([:not-present \c]
[:found \o]
[:found \u]
[:not-present \l]
[:not-present \d])
([:not-present \f]
[:found \o]
[:found \u]
[:found \n]
[:not-present \d])
([:found \y] [:found \o] [:found \u] [:found \n] [:found \g]))}
Copyright © 2022 Simon Brooke ([email protected])
This program and the accompanying materials are made available under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.