diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8e9407 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dataoutput diff --git a/prob.py b/prob.py new file mode 100644 index 0000000..3b2e0b7 --- /dev/null +++ b/prob.py @@ -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) diff --git a/solver.py b/solver.py new file mode 100644 index 0000000..54050cc --- /dev/null +++ b/solver.py @@ -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) + diff --git a/step2.py b/step2.py new file mode 100644 index 0000000..7097a24 --- /dev/null +++ b/step2.py @@ -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]) +