def test_part1_example1(self): content = dedent(""" ######### #[email protected]# ######### """) grid, starting_point = parse(content) self.assertEqual(part1(grid, starting_point), 8)
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)
def test_part1_example2(self): content = dedent(""" ######################## #[email protected].# ######################.# #d.....................# ######################## """) grid, starting_point = parse(content) self.assertEqual(part1(grid, starting_point), 86)
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)
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)
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))'))
def test_add(): a = parse('[1,2]') b = parse('[[3,4],5]') assert add(a, b) == [[1, 2], [[3, 4], 5]]
def test_magnitude4(): a = parse("[[[[1,1],[2,2]],[3,3]],[4,4]]") print(a) assert magnitude(a) == 445
def test_parse_brackets(self): result = day18.parse('2 * 3 + (4 * 5)', self.part1) assert (result == 26)
def test_magnitude2(): a = parse("[[9,1],[1,9]]") assert magnitude(a) == 129
def test_magnitude(): a = parse("[9,1]") assert magnitude(a) == 29
def test_parse(self): result = day18.parse('1 + 2 * 3 + 4 * 5 + 6', self.part1) assert (result == 71)
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)
def test_part2_example(self): result = day18.parse('1 + 2 * 3 + 4 * 5 + 6', self.part2) assert (result == 231)
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)
def test_many_brackets(self): result = day18.parse('((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2', self.part1) assert (result == 13632)
def test_magnitude3(): a = parse("[[[[0,7],4],[[7,8],[6,0]]],[8,1]]") print(a) assert magnitude(a) == 1384
def coprocessor_conflagration(input): instructions = parse(input) registers = defaultdict(int) return run_instructions(instructions, registers)