def main(): computer = IntCodeComputer('day_17.input') computer.set_io_format(IntCodeComputer.UNICODE) memory, _, _ = computer.save() result = [] # computer.run(output_data=result) # print("".join(result)) # rows = "".join(result).split() # intersections = [] # for y in range(len(rows) - 2): # for x in range(len(rows[y]) - 2): # if rows[y][x] == '#' and rows[y + 1][x] == '#' and rows[y - 1][x] == '#' and rows[y][x + 1] == '#' and rows[y][x - 1] == '#': # intersections.append((x, y)) # print(sum([x * y for x, y in intersections])) memory[0] = 2 computer.load(memory, 0, 0) # 'R,10,R,8,L,10,L,10,R,8,L,6,L,6,R,8,L,6,L,6,R,10,R,8,L,10,L,10,L,10,R,10,L,6,R,8,L,6,L,6,L,10,R,10,L,6,L,10,R,10,L,6,R,8,L,6,L,6,R,10,R,8,L,10,L,10' input_data = [ 'B,A,A,B,C,A,C,C,A,B\n', 'R,8,L,6,L,6\n', 'R,10,R,8,L,10,L,10\n', 'L,10,R,10,L,6\n', 'n\n' ] computer.run(input_data=[x for x in "".join(input_data)], output_data=result) print(result)
def test_day_2_part_1(self): computer = IntCodeComputer('day_2.input') program, counter, offset = computer.save() program[1] = 12 program[2] = 2 computer.load(program) computer.run() program, counter, offset = computer.save() self.assertEqual(3716293, program[0])
def test_unicode(self): computer = IntCodeComputer() computer.load([ 1006, 17, 16, 4, 17, 1001, 4, 1, 4, 1001, 1, 1, 1, 1105, 1, 0, 99, 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 0 ]) computer.set_io_format(IntCodeComputer.UNICODE) result = [] computer.run(output_data=result) self.assertEqual("Hello, World!", "".join(result))
def test_day_2_part_2(self): value = None for i in range(0, 100): for j in range(0, 100): computer = IntCodeComputer('day_2.input') program, counter, offset = computer.save() program[1] = i program[2] = j computer.load(program) computer.run() program, counter, offset = computer.save() if program[0] == 19690720: value = i * 100 + j break if value: break self.assertEqual(6429, value)
def main(): computer = IntCodeComputer('day_13.input') memory, counter, offset = computer.save() memory[0] = 2 computer.load(memory) in_data = [] out = 1 result = [] ball = None player = None while out: out = computer.run(input_data=in_data, output_data=result) game_plan = [result[x:x + 3] for x in range(0, len(result), 3)] color_map = {} for pixel in game_plan: if pixel[0] == -1 and pixel[1] == 0 and out == 0: print(pixel[2]) if pixel[2] == 3: player = (pixel[0], pixel[1]) if pixel[2] == 4: ball = (pixel[0], pixel[1]) color_map[(pixel[0], pixel[1])] = pixel[2] # print([x[1] for x in color_map.items()].count(2)) max_x = max([x[0] for x in game_plan]) min_x = min([x[0] for x in game_plan]) max_y = max([x[1] for x in game_plan]) min_y = min([x[1] for x in game_plan]) for y in range(min_y, max_y): print("".join([ get_tile((x, y), color_map) for x in range(min_x, max_x + 1) ])) if out == 1 and ball and player: if ball[0] < player[0]: in_data = [-1] elif ball[0] > player[0]: in_data = [1] else: in_data = [0]