def panels(program, initial_input): cells = {} c = IntCodeComputer(program) current_cell = (0,0) direction = (0,1) cells[current_cell] = initial_input while True: print("looping once") # first, give the input of the current panel if current_cell in cells: input = cells[current_cell] else: input = 0 c.add_input(input) o1 = c.compute() c.clear_output() if len(o1) == 0: return cells o2 = c.compute() c.clear_output() color = o1 # paint the cell! cells[current_cell] = color print(f"{current_cell} is now {color}") turn_direction = o2 direction = next_direction(direction, turn_direction) # then move! current_cell = ((current_cell[0] + direction[0]), (current_cell[1] + direction[1]))
def part2(program): c = IntCodeComputer(program, 2) c.add_input(2) c.compute() return c.output()
def part1(program): c = IntCodeComputer(program, 1) c.add_input(1) c.compute() return c.output()
from intcode import IntCodeComputer p1 = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99" c = IntCodeComputer( "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99", 0) c.compute() o = c.output() print(o) assert (o == p1) def part1(program): c = IntCodeComputer(program, 1) c.add_input(1) c.compute() return c.output() def part2(program): c = IntCodeComputer(program, 2) c.add_input(2) c.compute() return c.output() inpt = open("day9.input").read() #print(part1(inpt)) print(part2(inpt))