Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active February 17, 2022 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/aa57c27d63ca07b2d6942d0a99aa8416 to your computer and use it in GitHub Desktop.
Save zeffii/aa57c27d63ca07b2d6942d0a99aa8416 to your computer and use it in GitHub Desktop.
wordle solver simple.

wordle online may suppress words, like "slave".

"""
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
6 guesses
per guess we know
- if letter is in correct place, filter future words without the letter in that location
- if letter is present but not in correct place
- remove words without at least one occurrance of that letter
- remove words where the letter is present and in the current location
"""
word_set = set()
def make_word_set():
with open('wordlist2.csv') as f:
for l in f.readlines():
if l.strip():
word_set.add(l.strip())
def letters_on_places(word, locked_positions):
for idx, letter in enumerate(locked_positions):
if letter.strip():
if word[idx] == letter:
continue
else:
return
return word
def filter_words(not_containing=None, containing=None, locked_positions=None):
"""
not containing: string of letters
containing: string of letters
locked: string of letters , like: "A E "
where space indicates not yet locked.
"""
potentials = set()
for w in word_set:
if not (set(w) & set(not_containing)):
if containing:
if set(w) > set(containing):
potentials.add(w)
else:
potentials.add(w)
possible_locked = []
sorted_potentials = sorted(list(potentials))
for word in sorted_potentials:
if locked_positions:
result = letters_on_places(word, locked_positions)
if result:
possible_locked.append(result)
return possible_locked
make_word_set()
potentials = filter_words(not_containing="monyplt", containing="sv", locked_positions=" a e ")
print(potentials)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment