Ejemplo n.º 1
0
 def test_part1_example1(self):
     content = dedent("""
         #########
         #[email protected]#
         #########
         """)
     grid, starting_point = parse(content)
     self.assertEqual(part1(grid, starting_point), 8)
Ejemplo n.º 2
0
 def test_part1_example3(self):
     content = dedent("""
         ########################
         #...............b.C.D.f#
         #.######################
         #[email protected]#
         ########################
         """)
     grid, starting_point = parse(content)
     self.assertEqual(part1(grid, starting_point), 132)
Ejemplo n.º 3
0
 def test_part1_example2(self):
     content = dedent("""
         ########################
         #[email protected].#
         ######################.#
         #d.....................#
         ########################
         """)
     grid, starting_point = parse(content)
     self.assertEqual(part1(grid, starting_point), 86)
Ejemplo n.º 4
0
 def test_part1_example5(self):
     content = dedent("""
         ########################
         #@..............ac.GI.b#
         ###d#e#f################
         ###A#B#C################
         ###g#h#i################
         ########################
         """)
     grid, starting_point = parse(content)
     self.assertEqual(part1(grid, starting_point), 81)
Ejemplo n.º 5
0
 def test_part1_example4(self):
     content = dedent("""
         #################
         #i.G..c...e..H.p#
         ########.########
         #j.A..b...f..D.o#
         ########@########
         #k.E..a...g..B.n#
         ########.########
         #l.F..d...h..C.m#
         #################
         """)
     grid, starting_point = parse(content)
     self.assertEqual(part1(grid, starting_point), 136)
Ejemplo n.º 6
0
 def testParse(self):
     self.assertEqual(71, parse('1 + 2 * 3 + 4 * 5 + 6'))
     self.assertEqual(26, parse('2 * 3 + (4 * 5)'))
     self.assertEqual(13632, parse('((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2'))
     self.assertEqual(12240, parse('5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))'))
Ejemplo n.º 7
0
def test_add():
    a = parse('[1,2]')
    b = parse('[[3,4],5]')

    assert add(a, b) == [[1, 2], [[3, 4], 5]]
Ejemplo n.º 8
0
def test_magnitude4():
    a = parse("[[[[1,1],[2,2]],[3,3]],[4,4]]")
    print(a)

    assert magnitude(a) == 445
Ejemplo n.º 9
0
 def test_parse_brackets(self):
     result = day18.parse('2 * 3 + (4 * 5)', self.part1)
     assert (result == 26)
Ejemplo n.º 10
0
def test_magnitude2():
    a = parse("[[9,1],[1,9]]")

    assert magnitude(a) == 129
Ejemplo n.º 11
0
def test_magnitude():
    a = parse("[9,1]")

    assert magnitude(a) == 29
Ejemplo n.º 12
0
 def test_parse(self):
     result = day18.parse('1 + 2 * 3 + 4 * 5 + 6', self.part1)
     assert (result == 71)
Ejemplo n.º 13
0
 def test_part2_many_brackets_second_example(self):
     result = day18.parse('((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2',
                          self.part2)
     print(result)
     assert (result == 23340)
Ejemplo n.º 14
0
 def test_part2_example(self):
     result = day18.parse('1 + 2 * 3 + 4 * 5 + 6', self.part2)
     assert (result == 231)
Ejemplo n.º 15
0
 def test_many_brackets_second_example(self):
     result = day18.parse('5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))',
                          self.part1)
     assert (result == 12240)
Ejemplo n.º 16
0
 def test_many_brackets(self):
     result = day18.parse('((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2',
                          self.part1)
     assert (result == 13632)
Ejemplo n.º 17
0
def test_magnitude3():
    a = parse("[[[[0,7],4],[[7,8],[6,0]]],[8,1]]")
    print(a)

    assert magnitude(a) == 1384
Ejemplo n.º 18
0
def coprocessor_conflagration(input):
    instructions = parse(input)
    registers = defaultdict(int)

    return run_instructions(instructions, registers)