-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve.py
47 lines (36 loc) · 1.4 KB
/
solve.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
from itertools import permutations
def load_words():
print('Parcing wordlist')
with open('combined.txt') as word_file:
valid_words = set(word_file.read().split())
return valid_words
def valdate_words(words):
for i in filter(lambda x: x in word_list, words):
yield i
def get_permutations_recurse1(chars):
if len(chars) <= 2:
return chars
else:
chars_split_1 = chars[:len(chars)//2]
chars_split_2 = chars[len(chars)//2:]
return get_permutations_recurse1(chars_split_1),
get_permutations_recurse1(chars_split_2), chars
def get_permutations_recurse2(chars, len):
# Recursive function that returns all string combnations in a tuple
#
if len == 3:
# Base case
string_combos = tuple([''.join(i) for i in permutations(chars, 3)])
return tuple([''.join(i) for i in permutations(chars, 3)])
else:
# Next loop the permutations will be one shorter
# This concatanates the tuples into a bigger tuple
string_combos = tuple([''.join(i) for i in permutations(chars, len)])
return string_combos + get_permutations_recurse2(chars, len - 1)
if __name__ == '__main__':
word_list = load_words()
print('Search wordlist for word')
input_chars = input('Word: ')
perms = get_permutations_recurse2(input_chars, len(input_chars))
for i in valdate_words(perms):
print(i)