Created
February 14, 2022 13:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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