-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
54 lines (45 loc) · 2.09 KB
/
run.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
50
51
52
53
54
import enchant
import argparse
import string
class BruteForceWordleSolver:
alphabet = set(string.ascii_lowercase)
d = enchant.Dict('en_US')
def __init__(self, args):
self.grays = {} if args.grays is None else set(args.grays)
self.yellows = self.dictionarize(args.yellows)
self.greens = self.dictionarize(args.greens)
self.yellows_list = set(self.yellows.values()).difference('?')
print('\nGreens :', self.greens)
print('Yellows:', self.yellows)
print('Grays :', self.grays)
print('\nValid wordles:')
def dictionarize(self, pair):
d = dict()
for i in range(1, 6):
d[i] = '?'
if pair is not None:
for row in pair:
d[int(row[1])] = row[0].lower()
return d
def valid_ith_alphabet(self, i):
# valid_ith_alphabet = lambda i: alphabet.difference(self.grays).difference(set(self.yellows[i])) if self.greens[i] == '?' else self.greens[i]
if self.greens[i] == '?':
return self.alphabet.difference(self.grays).difference(set(self.yellows[i]))
else:
return self.greens[i]
def run(self):
for _1 in self.valid_ith_alphabet(1):
for _2 in self.valid_ith_alphabet(2):
for _3 in self.valid_ith_alphabet(3):
for _4 in self.valid_ith_alphabet(4):
for _5 in self.valid_ith_alphabet(5):
word = f'{_1}{_2}{_3}{_4}{_5}'
if self.d.check(word) and all(x in word for x in self.yellows_list):
print(word)
if __name__ == '__main__':
parser = argparse.ArgumentParser('Brute Force Wordle Answer Generation Program')
parser.add_argument('--yellows', type=str, nargs='+', help='list {alphabet, index} pairs eg) a2 b3')
parser.add_argument('--greens', type=str, nargs='+', help='list {alphabet, index} pairs eg) c4 d5')
parser.add_argument('--grays', type=str, nargs='+', help='list alphabet eg) q w e')
args = parser.parse_args()
BruteForceWordleSolver(args).run()