Skip to content

Instantly share code, notes, and snippets.

@hoheinzollern
Created February 14, 2022 13:50
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 hoheinzollern/9297f84633a79cf42c074427aa24f72e to your computer and use it in GitHub Desktop.
Save hoheinzollern/9297f84633a79cf42c074427aa24f72e to your computer and use it in GitHub Desktop.
Returns all valid guesses from the linux dictionary: `y` defines the letters to be included, `n` defines the letters to be excluded, `g` contains a space where the character is unknown, the right letter otherwise, and `e` contains the excluded letters from each position
words = open('/usr/share/dict/words').read().splitlines()
l5w = list(filter(lambda x: len(x) == 5 and x.islower() and x.isalpha(), words))
def guess(y, n, g=' ', e=['','','','','']):
return list(
filter(
lambda x:
all(c in x for c in y) and
all(not(c in x) for c in n) and
all(g[i]==' ' or x[i]==g[i] for i in range(5)) and
all(not(x[i] in e[i]) for i in range(5)),
l5w))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment