-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (44 loc) · 1.34 KB
/
main.py
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
from random import choice
from load import dw
class Wordle:
def __init__(self, ans=None, mxt=6, outputs="CEN"):
if ans is None:
self.ans = choice(dw)
else:
self.ans = ans
self.mxt = mxt
self.t = 1
self.outputs = outputs
def inp(self, inp):
self.t += 1
if self.t <= self.mxt+1:
out = ""
for i in range(len(self.ans)):
if inp[i] == self.ans[i]:
out += self.outputs[0]
elif inp[i] in self.ans:
out += self.outputs[1]
else:
out += self.outputs[2]
if inp == self.ans:
return 1
else:
return out
else:
return 0
class RawSolver:
def __init__(self, word_set=dw, outputs="CEN"):
self.outputs = outputs
self.available = word_set.copy()
def inp(self, res, word):
unavailable_indexes = []
for i in range(len(self.available)):
cur = self.available[i]
if Wordle(cur).inp(word) != res:
unavailable_indexes.append(i)
unavailable_indexes.reverse()
for index in unavailable_indexes:
del self.available[index]
return self
def get(self):
return self.available