-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver.py
29 lines (29 loc) · 804 Bytes
/
solver.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
WORDLIST_FILENAME = "words.txt"
def load_words():
print("Loading word list from file...")
with open(WORDLIST_FILENAME) as f:
word_list = ''.join(f.readlines()).split()
print(" ", len(word_list), "words loaded.")
return word_list
def permutation(s):
if len(s)==1:
return s
else:
result=[]
for i in range(0,len(s)):
# return s+all('')
p=permutation(s[:i]+s[i+1:])
for word in p:
result.append(s[i]+word)
return result
def unique(words):
return list(set(words))
word_list=load_words()
def word_finder(s):
guesses=permutation(s)
result=[]
for word in guesses:
if word in word_list:
result.append(word)
return result
print(unique(word_finder('treat')))