candi = (curr[0] + direc[0], curr[1] + direc[1]) if in_map(candi, scaff) and scaff[candi[1]][candi[0]] == "#": curr = candi seg_len += 1 else: cmds.append(seg_len) seg_len = 0 for side_direc in get_side_dir(curr, direc, scaff): if scaff[curr[1] + side_direc[0][1]][curr[0] + side_direc[0][0]] == "#": direc = side_direc[0] cmds.append(side_direc[1]) break direc = (0, 0) move = ["A,B,A,B,C,C,B,A,B,C\n", "L,12,L,10,R,8,L,12\n", "R,8,R,10,R,12\n", "L,10,R,12,R,8\n", "n\n"] for item in move: while ascii_interface.status == "awaiting output": # Discard prompts ascii_interface.output_signal() for val in item: ascii_interface.input_signal(ord(val)) # Read in instructions final = [] while ascii_interface.status == "awaiting output": # Outputs the map at the end, DISCARD final.append(ascii_interface.output_signal()) print(final[-1]) # THIS IS A FK'N MESS. JUST NO
from itertools import permutations from intcode import Intcode high = -999999999999999999999999999999999999 p = permutations(range(5, 10)) for i in p: a = Intcode() b = Intcode() c = Intcode() d = Intcode() e = Intcode() a.input_signal(i[0]) b.input_signal(i[1]) c.input_signal(i[2]) d.input_signal(i[3]) e.input_signal(i[4]) outE = 0 while a.status != "halted": a.input_signal(outE) outA = a.output_signal() b.input_signal(outA) outB = b.output_signal() c.input_signal(outB) outC = c.output_signal()
from intcode import Intcode robot = Intcode() cr = (0, 0) fr = (0, 1) panels = {cr : 1} while robot.status != "halted": if cr not in panels: panels[cr] = 0 robot.input_signal(panels[cr]) panels[cr] = robot.output_signal() direction = robot.output_signal() if direction == 0: # left fr = (fr[1], -fr[0]) else: # right fr = (-fr[1], fr[0]) cr = (cr[0] + fr[0], cr[1] + fr[1]) m = [["0"] * 43 for i in range(6)] for panel in panels: m[-panel[1]][-panel[0]] = str(panels[panel]) for i in m: i[:] = [" " if j == "0" else j for j in i]
from intcode import Intcode game = Intcode() level = [[0] * 44 for _ in range(20)] score = 0 # 0 -> 43, 0 -> 19 # 3874 while game.status != "halted": if game.status == "awaiting output": x = game.output_signal() y = game.output_signal() t_id = game.output_signal() if x == -1 and y == 0: score = t_id else: level[y][x] = t_id elif game.status == "awaiting input": game.input_signal(0) print(score)
from intcode import Intcode a = Intcode() a.input_signal(2) c = [] while a.status != "halted": c.append(a.output_signal()) print(c)
def probe_location(x, y): drone = Intcode() drone.input_signal(x) drone.input_signal(y) return drone.output_signal()
robot = Intcode() cells = {(0, 0): 1, (0, 1): 0, (1, 0): 0, (0, -1): 0, (-1, 0): 0} oxygen = None unknown_cells = {(0, 1), (1, 0), (0, -1), (-1, 0)} robot_cell = (0, 0) while unknown_cells: unknown_cell = unknown_cells.pop() path = short_path(robot_cell, unknown_cell, cells) report = None for step in path: robot.input_signal(coord_to_dir(robot_cell, step)) report = robot.output_signal() if report: robot_cell = step cells[unknown_cell] = report if report: nbr_list = nbrs(robot_cell) for nbr in nbr_list: if nbr not in cells: cells[nbr] = 0 unknown_cells.add(nbr) if report == 2: oxygen = unknown_cell
from intcode import Intcode network = [] for i in range(50): new_net_comp = Intcode() new_net_comp.input_signal(i) network.append(new_net_comp) del new_net_comp del i packets = [] nat = None last_nat_y = None while True: for net_comp in network: if net_comp.status == "awaiting input": net_comp.input_signal(-1) while net_comp.status == "awaiting output": address = net_comp.output_signal() x = net_comp.output_signal() y = net_comp.output_signal() if address == 255: nat = (0, x, y) else: packets.append((address, x, y)) if not packets: