-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolver.py
More file actions
58 lines (49 loc) · 1.55 KB
/
solver.py
File metadata and controls
58 lines (49 loc) · 1.55 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
import json
allwords = open('wordList.txt', 'r').read().splitlines()
wordList = []
for word in allwords:
split = word.split(',')
wordList.append((int(split[0]), split[2], int(split[1])))
charDict = json.load(open('charDict.json'))
order = []
while(len(wordList) > 1):
num = 1
no = []
val, guess, f = wordList[0]
print("narrowed down to: " + str(len(wordList)) + " words")
input("guess: " + guess)
s = input("What was the result?\n")
for i in range(len(s)):
c = s[i]
if c.isupper():
c = c.lower()
num *= charDict[c]['green'][i] * charDict[c]['yellow']
for i in range(len(s)):
c = s[i]
if c == '_':
c = guess[i]
no.append(charDict[c]['green'][i])
count = 1
temp = num
while(True):
if temp % charDict[c]['yellow'] == 0:
count += 1
temp = temp/charDict[c]['yellow']
else:
break
no.append(charDict[c]['yellow']**count)
elif c.islower():
num *= charDict[c]['yellow']
no.append(charDict[c]['green'][i])
for i in range(len(wordList)-1, -1, -1):
val, guess, freq = wordList[i]
if val % num != 0:
wordList.pop(i)
continue
for n in no:
if val % n == 0:
wordList.pop(i)
break
if (len(wordList) < 100):
wordList.sort(key=lambda x: x[2], reverse=True)
print("answer is " + wordList[0][1])