-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·60 lines (51 loc) · 1.6 KB
/
main.py
File metadata and controls
executable file
·60 lines (51 loc) · 1.6 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
59
60
#!/usr/bin/env python3
from pyreadline3 import Readline
readline = Readline()
wordlist = []
try:
with open("words.txt", "r") as f:
for line in f:
wordlist.append(line.strip().replace('qu', 'Q'))
except EnvironmentError:
print("Cannot find wordlist")
exit(1)
while True:
try:
valid_words = []
letters = input(f'> ')
if " " in letters:
rack, preference = letters.split()
if "$" in preference:
preference_status = "suffix"
if "^" in preference:
preference_status = "prefix"
else:
rack = letters
preference = None
for word in wordlist:
candidate = True
rack_letters = list(rack)
for letter in word:
if letter not in rack_letters:
candidate = False
break
else:
rack_letters.remove(letter)
if candidate:
valid_words.append([len(word), word])
valid_words.sort()
for entry in valid_words:
length = entry[0]
word = entry[1].replace('Q', 'qu')
if preference:
candidate = True
for letter in list(preference):
if not str(letter) in word:
candidate = False
if candidate:
print(f'{str(length)} {word}')
else:
print(f'{str(length)} {word}')
except (KeyboardInterrupt, EOFError):
print("Exiting")
exit(1)