Exemplo n.º 1
0
        field[x, y] = kind

    y, x, score = next(pixels)
    print(f'Score: {score}')


def update_pixel(update, field):
    y, x, kind = update
    if y != -1:
        field[x, y] = kind
    else:
        print(f'Score: {kind}')


arcade = IntCode(instructions, inputs=inputs)
init_display, code = arcade.intcode()


read_field(init_display, field)
plt.imshow(field)
plt.show()


while code != ReturnCode.BREAK:
    changes, code = arcade.intcode()
    changes = chunked(changes, 3)
    for change in changes:
        update_pixel(change, field)

    # plt.imshow(field)
    # plt.show()
Exemplo n.º 2
0
    Direction.WEST: Direction.SOUTH,
    Direction.SOUTH: Direction.EAST,
    Direction.EAST: Direction.NORTH,
}

turn_right = {
    Direction.NORTH: Direction.EAST,
    Direction.WEST: Direction.NORTH,
    Direction.SOUTH: Direction.WEST,
    Direction.EAST: Direction.SOUTH,
}

instructions = read_instructions('input17.txt')

space_roomba = IntCode(instructions)
output, rc = space_roomba.intcode()

split_output = list(split_at(output, lambda x: x == 10))
scaffold = np.array(split_output[:-2])

cur_roomba_coords = Point(*np.argwhere(scaffold == ord('^'))[0])
cur_direction = Direction.NORTH
steps = []
step_count = 0

xrange = range(scaffold.shape[0])
yrange = range(scaffold.shape[1])

while True:

    coords_after_step = cur_roomba_coords + directions[cur_direction]