Skip to content

Commit 0798198

Browse files
StardustRLAdrien227
authored andcommitted
Filter the words list
1 parent 154ee60 commit 0798198

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

wordle_solver/wordle_solver.py

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# https://github.com/dwyl/english-words for the list of words
22

3+
from audioop import add
4+
from operator import contains
5+
from re import L
6+
import string
7+
from typing import Set
38
from selenium import webdriver
49
from selenium.webdriver.firefox.service import Service as FirefoxService
510
from webdriver_manager.firefox import GeckoDriverManager
@@ -10,5 +15,89 @@ def main():
1015
browser = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
1116
browser.get("https://www.nytimes.com/games/wordle/index.html")
1217

18+
#From the basic list of words, return all the words with 5 characters.
19+
def get_list_of_five():
20+
21+
filtered_list = []
22+
23+
file = open("words_alpha.txt","r")
24+
25+
for line in file :
26+
data = line.strip().split(',')
27+
#print('word : ',data)
28+
#print('length : ',len(line))
29+
if (len(line) == 6) :
30+
#print("le mot ",data," est ajoute")
31+
filtered_list.append(line)
32+
33+
file.close()
34+
return filtered_list
35+
36+
#Print to verify filtered_list only contains 5 characters words.
37+
#for line in filtered_list :
38+
#print(line,end="")
39+
40+
41+
#Algorithm that solve the wordle
42+
#In the string we get :
43+
# _ : the letter is not on the right position (present)
44+
# * : the letter is not in the solution (absent)
45+
# X : the letter is on the right position (correct)
46+
# letters_not_in_response, is a list which keeps track of the allowed letters
47+
# letter_not_in_position, is a list which keeps track of the letters in bad position
48+
# For exemple, "A_A_*A", letters_not_in_response = ['B'], letter_not_in_position = ['K'].
49+
def solving_algorithm():
50+
51+
print("solving_algorithm start")
52+
53+
list_of_words = get_list_of_five()
54+
absent_letters = set([])
55+
present_letters = set([])
56+
57+
solution = "mbron"#developpement solution
58+
solving_string = "*****"
59+
60+
test_1 = "abdki"
61+
62+
for letter in range(len(test_1)):
63+
print("letter : ",test_1[letter])
64+
if(test_1[letter] == solution[letter]): #Case when the status of the letter is "correct"
65+
print("letters in the right position : ", solution[letter])
66+
print("GREATOOOOO")
67+
solving_string = solving_string[:letter]+test_1[letter]+solving_string[letter+1:]
68+
elif():#status is present
69+
print("the letter is present")
70+
solving_string = solving_string[:letter]+"_"+solving_string[letter+1:]
71+
present_letters.add(test_1[letter])
72+
else :#status is absent
73+
print("the letter is absent")
74+
absent_letters.add(test_1[letter]) #Case when the status of the letter is 'absent'
75+
solving_string = solving_string[:letter]+"*"+solving_string[letter+1:]
76+
77+
78+
print("Update list of word")
79+
print("lenght of list", len(list_of_words))
80+
#Update list of words
81+
buffer_list = []
82+
83+
for word in list_of_words :
84+
print(word)
85+
for absent in absent_letters :
86+
print(absent)
87+
if absent in word :
88+
break
89+
buffer_list.append(word)
90+
91+
list_of_words = buffer_list
92+
93+
94+
print("letter not in the right position : ",present_letters)
95+
print("Letters with absent status",absent_letters)
96+
print("solving string :", solving_string)
97+
#print(list_of_words)
98+
print("lenght of list", len(buffer_list))
99+
100+
101+
13102
if __name__ == "__main__":
14-
main()
103+
solving_algorithm()

0 commit comments

Comments
 (0)