Exemplo n.º 1
0
    def test_part_two(self):
        "Test part two example of Gates object"

        # 1. Create Gates object from text
        myobj = gates.Gates(part2=True, text=aoc_07.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
Exemplo n.º 2
0
    def test_part_one(self):
        "Test part one example of Gates object"

        # 1. Create Gates object from text
        myobj = gates.Gates(text=aoc_07.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
Exemplo n.º 3
0
    def test_empty_init(self):
        "Test the default Gates creation"

        # 1. Create default Gates object
        myobj = gates.Gates()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
        self.assertEqual(len(myobj.wires), 0)
Exemplo n.º 4
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = gates.Gates(part2=True, text=input_lines)

    # 2. Determine the solution for part two
    solution = solver.part_two(verbose=args.verbose, limit=args.limit)
    if solution is None:
        print("There is no solution")
    else:
        print("The solution for part two is %s" % (solution))

    # 3. Return result
    return solution is not None
Exemplo n.º 5
0
 def __init__(self, circuitDict, pBitOverride=None):
     """
     Circuit class to be computed by Alice. This means
     Alice knows the p
     """
     self.name = None
     self.alice = None
     self.bob = None
     self.gates = None
     self.out = None
     # processes json.
     self.processCircuit(circuitDict)
     # generate wire encryption keys
     self.generateWireKeys()
     # generate p bits
     self.generatePBits(override=pBitOverride)
     # load logic gates
     self.logic = gate.Gates()
Exemplo n.º 6
0
    def test_text_init(self):
        "Test the Gates object creation from text"

        # 1. Create Gates object from text
        myobj = gates.Gates(text=aoc_07.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 10)
        self.assertEqual(len(myobj.wires), 0)

        # 3. Check methods
        self.assertEqual(myobj.execute(["SET", 1, 1, "aa"]), 1)
        self.assertEqual(myobj.execute(["SET", 123, 123, "bb"]), 123)
        myobj.run_once()
        self.assertEqual(myobj.wires["d"], 72)
        self.assertEqual(myobj.wires["e"], 507)
        self.assertEqual(myobj.wires["f"], 492)
        self.assertEqual(myobj.wires["g"], 114)
        self.assertEqual(myobj.wires["h"], 65412)
        self.assertEqual(myobj.wires["i"], 65079)
        self.assertEqual(myobj.wires["x"], 123)
        self.assertEqual(myobj.wires["y"], 456)
        self.assertEqual(myobj.wires["a"], 114)