Exemplo n.º 1
0
    def part1(self):
        # print("Part1")
        count = 0
        for x in range(50):
            for y in range(50):
                this_value = solve1(self.program, [x, y])[0]
                # print(f"Got value {this_value}")
                if this_value == 1:
                    count += 1

        # print("part1:")
        return count
Exemplo n.º 2
0
    def part2(self):
        # print("Constructing")

        x_started = None
        x_stopped = None
        for y in range(1600):
            use_optimize = y > 7
            scan_range = range(10)
            if use_optimize:
                scan_range = range(x_started, x_stopped + 3)

            seen_light = False
            x_stopped_last = x_stopped
            x_stopped = None
            for x in scan_range:
                if use_optimize and seen_light and x <= x_stopped_last:
                    this_value = 1
                else:
                    this_value = solve1(self.program, [x, y])[0]

                self.grid[complex(x, y)] = this_value
                if this_value == 1:
                    self.filled_squares[complex(x, y)] = 1
                    if not seen_light:
                        seen_light = True
                        x_started = x
                if this_value == 0 and seen_light and x_stopped is None:
                    x_stopped = x
        # print("Done Constructing")

        # self.display()

        squares = sorted(self.filled_squares.keys(), key=manhattan)
        size = 99

        # print("Looking")
        for square in squares:
            if (square in self.filled_squares
                    and square + complex(size, 0) in self.filled_squares
                    and square + complex(0, size) in self.filled_squares
                    and square + complex(size, size) in self.filled_squares):
                # print("------")
                # print(square)
                return int(square.real) * 10_000 + int(square.imag)

                #                 self.grid[square] = "O"
                #                 self.grid[square + complex(0, size)] = "O"
                #                 self.grid[square + complex(size, size)] = "O"
                #                 self.grid[square + complex(size, 0)] = "O"
                #                 self.display()
                break
        return None
Exemplo n.º 3
0
 def test_prog1(self):
     test_prog1 = [
         109,
         1,
         204,
         -1,
         1001,
         100,
         1,
         100,
         1008,
         100,
         16,
         101,
         1006,
         101,
         0,
         99,
     ]
     outputs = solve1(test_prog1, [])
     # Quine
     self.assertEqual(outputs, test_prog1)
Exemplo n.º 4
0
 def test_day5_part2(self):
     file_data = parse("../../05/input.txt")
     got = solve1(file_data, [5])
     want = [11956381]
     self.assertEqual(want, got)
Exemplo n.º 5
0
 def test_day5_part1(self):
     file_data = parse("../../05/input.txt")
     got = solve1(file_data, [1])
     want = [0, 0, 0, 0, 0, 0, 0, 0, 0, 5821753]
     self.assertEqual(want, got)
Exemplo n.º 6
0
 def test_larger(self):
     program = Programs5.prog_larger
     self.assertEqual(solve1(program, [2]), [999])
     self.assertEqual(solve1(program, [8]), [1000])
     self.assertEqual(solve1(program, [12]), [1001])
Exemplo n.º 7
0
 def test_jump_2(self):
     program = [3, 3, 1105, -1, 9, 1101, 0, 0, 12, 4, 12, 99, 1]
     self.assertEqual(solve1(program, [0]), [0])
     self.assertEqual(solve1(program, [10]), [1])
Exemplo n.º 8
0
 def test_jump_1(self):
     program = [3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9]
     self.assertEqual(solve1(program, [0]), [0])
     self.assertEqual(solve1(program, [10]), [1])
Exemplo n.º 9
0
 def test_8_4(self):
     program = [3, 3, 1107, -1, 8, 3, 4, 3, 99]
     self.assertEqual(solve1(program, [7]), [1])
     self.assertEqual(solve1(program, [8]), [0])
     self.assertEqual(solve1(program, [9]), [0])
Exemplo n.º 10
0
 def test_8_2(self):
     program = [3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8]
     self.assertEqual(solve1(program, [7]), [1])
     self.assertEqual(solve1(program, [8]), [0])
     self.assertEqual(solve1(program, [9]), [0])
Exemplo n.º 11
0
 def test_part2(self):
     file_data = parse("../../09/input.txt")
     outputs = solve1(file_data, [2])
     self.assertEqual(outputs, [33343])
Exemplo n.º 12
0
 def test_part1(self):
     file_data = parse("../../09/input.txt")
     outputs = solve1(file_data, [1])
     self.assertEqual(outputs, [3780860499])
Exemplo n.º 13
0
 def test_prog3(self):
     test_prog3 = [104, 1125899906842624, 99]
     outputs = solve1(test_prog3, [])
     self.assertEqual(outputs, [1125899906842624])
Exemplo n.º 14
0
 def test_prog2(self):
     test_prog2 = [1102, 34915192, 34915192, 7, 4, 7, 99, 0]
     outputs = solve1(test_prog2, [])
     self.assertEqual(outputs, [1219070632396864])
Exemplo n.º 15
0
def amplify_once(program_in, phase_sequence):
    input_signal = 0
    for setting in phase_sequence:
        outputs = solve1(program_in, [setting, input_signal])
        input_signal = outputs[0]
    return input_signal