Beispiel #1
0
    def test_part_one(self):
        "Test part one example of Discs object"

        # 1. Create Discs object from text
        myobj = discs.Discs(text=aoc_15.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
Beispiel #2
0
    def test_part_two(self):
        "Test part two example of Discs object"

        # 1. Create Discs object from text
        myobj = discs.Discs(part2=True, text=aoc_15.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
Beispiel #3
0
    def test_empty_init(self):
        """Test default Discs creation"""

        # 1. Create default Jumps object
        mydiscs = discs.Discs()

        # 2. Make sure it has the default values
        self.assertEqual(mydiscs.part2, False)
        self.assertEqual(mydiscs.discs, {})
Beispiel #4
0
    def test_empty_init(self):
        "Test the default Discs creation"

        # 1. Create default Discs object
        myobj = discs.Discs()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
        self.assertEqual(myobj.sizes, [])
        self.assertEqual(myobj.positions, [])
Beispiel #5
0
    def test_text_init(self):
        "Test the Discs object creation from text"

        # 1. Create Discs object from text
        myobj = discs.Discs(text=aoc_15.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 2)
        self.assertEqual(myobj.sizes, [5, 2])
        self.assertEqual(myobj.positions, [4, 1])

        # 3. Check methods
        self.assertEqual(myobj.useCRT(), 5)
Beispiel #6
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = discs.Discs(part2=True, text=input_lines)

    # 2. Determine name of the bottom probram
    solution = solver.balance(verbose=args.verbose, limit=args.limit)
    if solution is None:
        print("There is no way to balance the programs")
    else:
        print("A program needs to change its weight to %s" % (solution))

    # 3. Return result
    return solution is not None
Beispiel #7
0
def part_one(args, input_lines):
    "Process part one of the puzzle"

    # 1. Create the puzzle solver
    solver = discs.Discs(part2=False, text=input_lines)

    # 2. Determine name of the bottom probram
    solution = solver.bottom(verbose=args.verbose, limit=args.limit)
    if solution is None:
        print("There is no bottom program")
    else:
        print("The bottom program is %s" % (solution))

    # 3. Return result
    return solution is not None
Beispiel #8
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = discs.Discs(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
Beispiel #9
0
    def test_value_init(self):
        """Test Discs creation with values"""

        # 1. Create Discs object with values
        mydiscs = discs.Discs(text=["pbga (66)", "xhth (57)"])

        # 2. Make sure it has the specified values
        self.assertEqual(mydiscs.part2, False)
        self.assertEqual(len(mydiscs.discs), 2)
        self.assertEqual("pbga" in mydiscs.discs, True)
        self.assertEqual("xxxx" in mydiscs.discs, False)
        self.assertEqual(mydiscs.discs["pbga"].weight, 66)
        self.assertEqual(mydiscs.discs["xhth"].weight, 57)

        # 3. Check methods
        self.assertEqual(mydiscs.number_above("pbga"), 0)
        self.assertEqual(mydiscs.number_above("xhth"), 0)
Beispiel #10
0
    def test_part_two(self):
        """Test Discs creation from text"""

        # 1. Create Jumps object from text
        mydiscs = discs.Discs(text=aoc_07.from_text(P1_EXAMPLES_TEXT),
                              part2=True)

        # 2. Make sure it has the specified values
        self.assertEqual(mydiscs.part2, True)
        self.assertEqual(len(mydiscs.discs), 13)
        self.assertEqual("pbga" in mydiscs.discs, True)
        self.assertEqual("xxxx" in mydiscs.discs, False)
        self.assertEqual(mydiscs.discs["pbga"].name, "pbga")
        self.assertEqual(mydiscs.discs["pbga"].weight, 66)
        self.assertEqual(mydiscs.discs["pbga"].above, [])
        self.assertEqual(mydiscs.discs["fwft"].name, "fwft")
        self.assertEqual(mydiscs.discs["fwft"].weight, 72)
        self.assertEqual(mydiscs.discs["fwft"].above, ["ktlj", "cntj", "xhth"])

        # 3. Check methods
        self.assertEqual(mydiscs.number_above("pbga"), 0)
        self.assertEqual(mydiscs.number_above("xhth"), 0)
        self.assertEqual(mydiscs.number_above("fwft"), 3)
        self.assertEqual(mydiscs.number_above("tknk"), 12)
        self.assertEqual(mydiscs.bottom(), "tknk")

        # 4. Check part two methods
        # ugml + (gyxo + ebii + jptl) = 68 + (61 + 61 + 61) = 251
        # padx + (pbga + havc + qoyq) = 45 + (66 + 66 + 66) = 243
        # fwft + (ktlj + cntj + xhth) = 72 + (57 + 57 + 57) = 243
        self.assertEqual(mydiscs.weight_above("gyxo"), 61)
        self.assertEqual(mydiscs.weight_above("ugml"), 251)
        self.assertEqual(mydiscs.weight_above("padx"), 243)
        self.assertEqual(mydiscs.weight_above("fwft"), 243)

        self.assertEqual(mydiscs.adjustment("tknk"), 243 - 251)
        self.assertEqual(mydiscs.adjustment("ugml"), 0)
        self.assertEqual(mydiscs.balance(), 60)
Beispiel #11
0
    def test_text_init(self):
        """Test Discs creation from text"""

        # 1. Create Jumps object from text
        mydiscs = discs.Discs(text=aoc_07.from_text(P1_EXAMPLES_TEXT))

        # 2. Make sure it has the specified values
        self.assertEqual(mydiscs.part2, False)
        self.assertEqual(len(mydiscs.discs), 13)
        self.assertEqual("pbga" in mydiscs.discs, True)
        self.assertEqual("xxxx" in mydiscs.discs, False)
        self.assertEqual(mydiscs.discs["pbga"].name, "pbga")
        self.assertEqual(mydiscs.discs["pbga"].weight, 66)
        self.assertEqual(mydiscs.discs["pbga"].above, [])
        self.assertEqual(mydiscs.discs["fwft"].name, "fwft")
        self.assertEqual(mydiscs.discs["fwft"].weight, 72)
        self.assertEqual(mydiscs.discs["fwft"].above, ["ktlj", "cntj", "xhth"])

        # 3. Check methods
        self.assertEqual(mydiscs.number_above("pbga"), 0)
        self.assertEqual(mydiscs.number_above("xhth"), 0)
        self.assertEqual(mydiscs.number_above("fwft"), 3)
        self.assertEqual(mydiscs.number_above("tknk"), 12)
        self.assertEqual(mydiscs.bottom(), "tknk")