add scripts

This commit is contained in:
randomuser 2022-02-07 00:21:18 -06:00
parent 4eb18bbb87
commit a2c1fa9666
4 changed files with 114 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
dataoutput

36
prob.py Normal file
View File

@ -0,0 +1,36 @@
import pickle
fd = open("wordlist", "r")
words = [i.rstrip() for i in fd.readlines()]
print(words)
def generateOutput(inputword, correct):
res = [0, 0, 0, 0, 0]
for i in range(len(inputword)):
if inputword[i] == correct[i]:
res[i] = 2
elif inputword[i] in correct:
res[i] = 1
return tuple(res)
def probs(dataset):
res = {}
for i in dataset:
if i in res:
res[i] += 1
else:
res[i] = 1
return res
data = {}
for i in words:
data[i] = None
cache = []
for j in words:
cache.append(generateOutput(i, j))
print("cached {} {}".format(i, j))
data[i] = probs(cache)
fdtwo = open("dataoutput", "wb")
pickle.dump(data, fdtwo)

60
solver.py Normal file
View File

@ -0,0 +1,60 @@
#!/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])
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]
print(req)
except:
req = None
if req != None:
if req == j:
counter += 1
continue
else:
status = 0
if j in nocontain:
status = 0
counter += 1
for j in contains:
if not j 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)

17
step2.py Normal file
View File

@ -0,0 +1,17 @@
import pickle
rawdata = open("dataoutput", "rb")
data = pickle.load(rawdata)
buf = []
for i in data:
tot = 0
nums = 0
for j in data[i]:
tot += data[i][j]
nums += 1
buf.append([i, tot / nums])
buf.sort(key = lambda x: x[1])
print(buf[0])