Ejemplo n.º 1
0
 def test_example2(self):
     s = Solver(from_str="42")
     one, one_total_power = s.solve_part_one()
     two, two_total_power = s.solve_part_two()
     self.assertEqual(one, "21,61")
     self.assertEqual(one_total_power, 30)
     self.assertEqual(two, "232,251,12")
     self.assertEqual(two_total_power, 119)
Ejemplo n.º 2
0
 def test_example1(self):
     s = Solver(from_str="18")
     one, one_total_power = s.solve_part_one()
     two, two_total_power = s.solve_part_two()
     self.assertEqual(one, "33,45")
     self.assertEqual(one_total_power, 29)
     self.assertEqual(two, "90,269,16")
     self.assertEqual(two_total_power, 113)
Ejemplo n.º 3
0
 def test_example(self):
     # 4
     # 3          LG
     # 2    HG
     # 1 E     HM    LM
     #      0  16  1 17
     test_data = [1 << 16 | 1 << 17, 1 << 0, 1 << 1, 0]
     s = Solver(from_str='...')
     self.assertEqual(s.explore(test_data), 11)
Ejemplo n.º 4
0
 def test_part_one(self):
     # 4
     # 3                     XG XM RG RM
     # 2            PM    SM
     # 1 E TG TM PG    SG
     #      0 16  1 17  2 18  3 19  4 20
     part1_data = [
         1 << 0 | 1 << 1 | 1 << 2 | 1 << 16, 1 << 17 | 1 << 18,
         1 << 3 | 1 << 4 | 1 << 19 | 1 << 20, 0
     ]
     s = Solver(from_str='...')
     self.assertEqual(s.explore(part1_data), 31)
Ejemplo n.º 5
0
 def test_part_two(self):
     # 4
     # 3                     XG XM RG RM
     # 2            PM    SM
     # 1 E TG TM PG    SG                EG EM DG DM
     #      0 16  1 17  2 18  3 19  4 20  5 21  6 22
     part2_data = [
         1 << 0 | 1 << 1 | 1 << 2 | 1 << 5 | 1 << 6 | 1 << 16 | 1 << 21
         | 1 << 22, 1 << 17 | 1 << 18, 1 << 3 | 1 << 4 | 1 << 19 | 1 << 20,
         0
     ]
     s = Solver(from_str='...')
     self.assertEqual(s.explore(part2_data), 55)
Ejemplo n.º 6
0
    def test_check_states(self):
        s = Solver(from_str='...')
        cs = s.get_check_state((1, [1 << 16 | 1 << 17, 1 << 0, 1 << 1, 0]))
        hs = "1" + "00030000" + "00000001" + "00000002" + "00000000"
        self.assertEqual(s.hash_state(cs), hs)
        cs = s.get_check_state((1, [1 << 18 | 1 << 19, 1 << 2, 1 << 3, 0]))
        self.assertEqual(s.hash_state(cs), hs)

        cs = s.get_check_state((1, [1 << 0, 1 << 16, 1 << 1 | 1 << 17, 0]))
        hs = "1" + "00000001" + "00010000" + "00020002" + "00000000"
        self.assertEqual(s.hash_state(cs), hs)
        cs = s.get_check_state((1, [1 << 1, 1 << 17, 1 << 0 | 1 << 16, 0]))
        self.assertEqual(s.hash_state(cs), hs)
Ejemplo n.º 7
0
 def test_examples(self):
     assert (not Solver.valid_password('hijklmmn'))
     assert (not Solver.valid_password('abbceffg'))
     assert (not Solver.valid_password('abbcegjk'))
     assert (Solver.valid_password('abcdffaa'))
     assert (Solver.valid_password('ghjaabcc'))
     assert (Solver.valid_password('hxbxxyzz'))
     assert (Solver.next_password('abcdefgh') == 'abcdffaa')
Ejemplo n.º 8
0
 def test_solution(self):
     s = Solver(from_str='hxbxwxba')
     one = s.solve_part_one()
     assert (one == 'hxbxxyzz')
Ejemplo n.º 9
0
 def test_solution(self):
     (one, two) = Solver(from_file="input/december11.input").solve()
     self.assertEqual(one, "21,54")
     self.assertEqual(two, "236,268,11")