wordlefish/solver.py

64 lines
1.9 KiB
Python

#!/usr/bin/python3
words = [i.rstrip() for i in open("wordlist", "r").readlines()]
nocontain = []
contains = []
defcontains = []
while True:
line = input("? ")
if line.split(' ')[0] == "add":
# rules parser
string = line.split(' ')[1]
splitted = [(string[i:i+2]) for i in range(0, len(string), 2)]
count = 0
for i in splitted:
if i[0] == "n":
nocontain.append(i[1])
print("\033[47;97m {} ".format(i[1]), end="")
elif i[0] == "y":
contains.append((i[1], count))
print("\033[103;97m {} ".format(i[1]), end="")
elif i[0] == "g":
defcontains.append((i[1], count))
print("\033[102;97m {} ".format(i[1]), end="")
print("\033[0m")
count += 1
elif line.split(' ')[0] == "reduce":
buf = []
for i in words:
counter = 0
status = 1
for j in i:
if status == 0: break
try:
req = [item[0] for item in defcontains if item[1] == counter][0]
except:
req = None
nothere = [item[0] for item in contains if item[1] == counter]
if req != None:
if req == j:
counter += 1
continue
else:
status = 0
for k in nothere:
if k == j:
status = 0
if j in nocontain:
status = 0
counter += 1
for j in contains:
if not j[0] in i:
status = 0
if status == 1:
buf.append(i)
words = buf
elif line.split(' ')[0] == "listbuffers":
print(nocontain, contains, defcontains)
elif line.split(' ')[0] == "words":
print(words)