-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.py
More file actions
44 lines (27 loc) · 1.09 KB
/
helper.py
File metadata and controls
44 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from wordle import LetterState
def count_letters(letter: str, word, state: list[LetterState]) -> int:
count = 0
for i in range(5):
if word[i] == letter and (state[i] == LetterState.CORRECT or state[i] == LetterState.INCLUDE):
count += 1
return count
def possible_words(possible: list[str], _guess: tuple[str, list[LetterState]]) -> list[str]:
out = []
for word in possible:
guess, state = _guess
for i in range(5):
letter = word[i]
s = state[guess.find(letter)]
if letter in guess and s == LetterState.NONE:
break
if state[i] == LetterState.INCLUDE and letter == guess[i]:
break
if state[i] == LetterState.INCLUDE and guess[i] not in word:
break
if state[i] == LetterState.CORRECT and guess[i] is not letter:
break
if count_letters(word[i], guess, state) > count_letters(word[i], word, [LetterState.CORRECT] * 5):
break
else:
out.append(word)
return out