예제 #1
0
    def solve(self):
        # Check if solvable
        if len(self.letters) > 10:
            print("Unsolvable, too many letters.")
            return 0

        # Setup variables dictionary, -1 for unassigned letters
        AC3_Crypt.setupAC3(self.cons, self.vars)
        keys = list(self.vars.keys())
        #keys = sorted(self.vars.keys(), key = lambda x: len(self.vars[x].domain))
        for k in keys:
            print(k, len(self.vars[k].domain))
        return self.backtrace(self.cons, self.vars, keys, 0)
예제 #2
0
    def solve(self):
        # Check if solvable
        if len(self.letters) > 10:
            print("Unsolvable, too many letters.")
            return 0

        # Setup variables dictionary, -1 for unassigned letters
        AC3_Crypt.setupAC3(self.cons, self.vars)
        keys = list(self.vars.keys())
        #keys = sorted(self.vars.keys(), key = lambda x: len(self.vars[x].domain))
        for k in keys:
            print(k, len(self.vars[k].domain))
        return self.backtrace(self.cons, self.vars, keys, 0)
예제 #3
0
    def solve(self):
        # Check if solvable
        if len(self.letters) > 10:
            print("Unsolvable, too many letters.")
            return 0

        t = time.time()
        # Setup the variables and constraints, runs AC3 once.
        AC3_Crypt.setupAC3(self.cons, self.vars)

        keys = list(self.vars.keys())
        #keys = sorted(self.vars.keys(), key = lambda x: len(self.vars[x].domain))
        #for k in keys:
        #print(k, len(self.vars[k].domain))
        final = self.backtrace(self.cons, self.vars, keys, 0)

        t = time.time() - t
        print("MAC Time Taken: ", t)
        print("MAC Nodes Explored: ", self.nodesExplored)
        return final
예제 #4
0
def runAC3():
    const = []
    vars = dict()
    AC3_Crypt.setupAC3(const, vars)
    AC3_Crypt.AC3(const, vars, None)