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]))
Beispiel #2
0
def part2(program):
    c = IntCodeComputer(program, 2)
    c.add_input(2)
    c.compute()
    return c.output()
Beispiel #3
0
def part1(program):
    c = IntCodeComputer(program, 1)
    c.add_input(1)
    c.compute()
    return c.output()