Exemplo n.º 1
0
                if result_direction == OUTPUT_TURN_RIGHT
                else (direction_idx - 1 + len(directions))
            ) % len(directions)
            position = (
                position[0] + directions[direction_idx][0],
                position[1] + directions[direction_idx][1],
            )
    return point_colors


def paint_output(painted_grid: dict):
    minx = min(painted_grid, key=lambda tile: tile[0])[0]
    maxx = max(painted_grid, key=lambda tile: tile[0])[0]

    miny = min(painted_grid, key=lambda tile: tile[1])[1]
    maxy = max(painted_grid, key=lambda tile: tile[1])[1]

    for y in range(miny, maxy + 1):
        row = ""
        for x in range(minx, maxx + 1):
            row += "#" if painted_grid.get((x, y)) == COLOR_WHITE else " "
        print(row)


instructions = IntCode.read_instructions(sys.argv[1])

print(f"Panels: {len(get_painted_grid(instructions.copy(), COLOR_BLACK))}")

paint_output(get_painted_grid(instructions.copy(), COLOR_WHITE))

Exemplo n.º 2
0
from intcode import IntCode

INPUT_DEBUG = 1
INPUT_BOOST = 2

instructions = IntCode.read_instructions("input.txt")
intcode = IntCode(instructions).with_input(INPUT_BOOST)
result = 0
while result is not None:
    result = intcode.run_instructions()
    if result is not None:
        print(f"Output: {result}")