def part_2(data): data[0] = 2 game = IntCode(data, []) game.calculate() i = 0 cnt = 0 GRID = [[' . ' for i in range(44)] for j in range(23)] while not game.is_halted() and cnt < 10: screen = game.get_output(-1) i = 0 while i < len(screen): [x, y, tile] = screen[i:i + 3] if x == -1 and y == 0: print(tile) i += 3 continue GRID[y][x] = t[tile] i += 3 disp(GRID) game.unpause([0, 0, 0]) game.calculate() cnt += 1 print('END OF PART2') return
def part_1(data): boost = IntCode(data, [1]) boost.calculate() print('END OF PART1') return
def part_2(data): boost = IntCode(data, [2]) boost.calculate() print('END OF PART2') return
def part_1(data): game = IntCode(data, []) game.calculate() screen = game.get_output(-1) i = 0 cnt = 0 while i < len(screen): [x, y, tile] = screen[i:i + 3] if tile == 2: cnt += 1 i += 3 print(cnt) # disp(GRID) print('END OF PART1') return
def part_1(data): perms = it.permutations(orig_list_1) thruster = 0 for p in perms: output = 0 for phase in p: amp_data = [phase] if output is not None: amp_data += [output] amp = IntCode(data, amp_data) amp.calculate() output = amp.get_output() if output > thruster: thruster = output print(thruster) print('END OF PART1') return
def part_2(data): GRID = [['.' for i in range(100)] for j in range(100)] code = IntCode(data) r_pos = (0, 0) r_d = 'N' panels = {r_pos: 1} while not code.is_halted(): try: in_data = [panels[r_pos]] except: in_data = [0] code.unpause(in_data) code.calculate() [color, d] = code.get_output(2) panels[r_pos] = color GRID[50 + r_pos[1]][50 + r_pos[0]] = '#' if color == 1 else '.' r_pos, r_d = get_new_pos(r_pos, r_d, d) disp(GRID) print('END OF PART2') #CBLPJZCU return
def part_1(data): code = IntCode(data) r_pos = (0, 0) r_d = 'N' panels = {r_pos: 0} painted = set() while not code.is_halted(): try: in_data = [panels[r_pos]] except: in_data = [0] code.unpause(in_data) code.calculate() [color, d] = code.get_output(2) painted |= {r_pos} panels[r_pos] = color r_pos, r_d = get_new_pos(r_pos, r_d, d) print(len(painted)) print('END OF PART1') return