-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordle bot.py
More file actions
76 lines (62 loc) · 2.6 KB
/
wordle bot.py
File metadata and controls
76 lines (62 loc) · 2.6 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
file = open("possibleWordleWords.txt", "r")
contents = file.readlines()
for i in range(len(contents)):
contents[i - 1] = contents[i - 1].replace("\n", "")
def createList(var):
var = str(var)
outputList = []
for i in range(len(var)):
outputList.append(var[i])
return outputList
def removeWords(x, needToDelete):
return not x in needToDelete
#get data for narrowing words down and put them in variables
requiredLetters = input("What are the required letters? (don't separate them using anything) ")
unavailableLetters = input("What are the unavailable letters? (don't separate them using anything) ")
order = input('What is the order of the word? (ex. if "a" is the first letter an you do not know the other letters, you would type a----) ')
order2 = input("Where do letters NOT go (same as last one, except put five rows, and you put letters that turn yellow instead of green) ")
for i in range(4):
order2 = f"{order2}{input("")}"
#turn vars into lists for itering
requiredLetterList = createList(requiredLetters)
unavailableLetterList = createList(unavailableLetters)
orderList = createList(order)
orderList2 = createList(order2)
#start narrowing down words
needToDelete = []
for i in contents:
for o in range(5):
if i[o] in unavailableLetterList and not i in needToDelete:
needToDelete.append(i)
for i in contents:
for o in requiredLetterList:
if not o in i and not i in needToDelete:
needToDelete.append(i)
for i in contents:
for idx in range(5):
if i[idx] != orderList[idx] and orderList[idx] != "-":
needToDelete.append(i)
idx = 0
for i in contents:
for o in range(5):
for index in range(5):
if idx == 25:
continue
if i[index] == str(orderList2[idx]) and i not in needToDelete:
needToDelete.append(i)
idx += 1
contents = list(filter(lambda x: removeWords(x, needToDelete), contents))
#order list into favorites first
favorites = []
letterFrequencies = {"a": 979, "b": 281, "c": 477, "d": 393, "e": 1233, "f": 230, "g": 311, "h": 389, "i": 671, "j": 27, "k": 210, "l": 719, "m": 316, "n": 575, "o": 754, "p": 367, "q": 29, "r": 899, "s": 669, "t": 729, "u": 467, "v": 153, "w": 195, "x": 37, "y": 425, "z": 40}
scores = {}
for word in contents:
score = 0
for key, val in letterFrequencies.items():
if key in word:
score += val
scores[word] = score
scores = dict(sorted(scores.items(), key = lambda item: item[1], reverse = True))
favorites = list(scores.keys())
print(len(favorites))
print(favorites)