Posted onEdited onWord count in article: 2.2kReading time ≈2 mins.
Wordle is a popular word puzzle developed
by Josh Wardle. The basic idea is to guess a given five letters'
word within six tries. After each guess, the letters are marked to show
if each letter is correct or is correct and in correct position. You can
find one here.
Here I present a half-manual simple solution to it.
According to Samuel
Morse, the letters ordered by its usage frequency is: E, T, A, I, N,
O, S, H, R, D, L, U, C, M, F, W, Y, G, P, B, V, K, Q, J, X, Z. We can
use the following program to choose 4 five-letters' words that cover 20
of most frequently used letters:
withopen('/usr/share/dict/words', 'r') asdict: distinctWords = [w.lower() for w inlist(filter(lambda word: feasible(word), dict.read().lower().splitlines()))] lessOftenLetters = ["v", "k", "q", "j", "x", "z"] words = list(filter(lambda word: len(set(list(word) + lessOftenLetters)) == len(lessOftenLetters) + 5, distinctWords)) for w1 in words: iflen(set(list(w1))) != 5: continue for w2 in words: iflen(set(list(w1 + w2))) != 10: continue for w3 in words: iflen(set(list(w1 + w2 + w3))) != 15: continue for w4 in words: iflen(set(list(w1 + w2 + w3 + w4))) != 20: continue print(w1 + " " + w2 + " " + w3 + " " + w4)
I picked cubit, dwarf, gnome,
and sylph. With these four words, we can get some
information about correct letters. Then we can use the following python
program to get a list of possible solution:
1 2 3 4 5 6 7 8 9
withopen('/usr/share/dict/words', 'r') asdict: print("Please input the correct letters without space:") inputLetters = list(set([l.lower() for l inlist(input())])) availableLetters = inputLetters + ["v", "k", "q", "j", "x", "z"] feasibleWords = list(filter(lambda word: len(word) == 5and word.isalpha(), dict.read().lower().splitlines())) for word in feasibleWords: iflen(list(filter(lambda letter: letter.lower() notin availableLetters, word))) == 0: iflen(set(filter(lambda letter: letter.lower() in inputLetters, word))) == len(inputLetters): print(word.upper())
This program does not consider the correct position of correct
letters thus that must be considered by the user herself. The dictionary
used in these programs contains a great number of words where many them
are hardly ever used. You can use your own dictionary instead of
course.