Example #1
0
def paint_hull(memory: list,
               initial_panel=PANELS.BLACK) -> Union[defaultdict, defaultdict]:
    program = IntcodeComputer(memory)
    loc = (0, 0)

    hull = defaultdict(lambda: PANELS.BLACK)
    hull[loc] = initial_panel
    painted = defaultdict(lambda: 0)

    res = IntcodeComputer.OUTPUT_CODES.OK
    facing = DIRECTION.NORTH
    while res != IntcodeComputer.OUTPUT_CODES.HALTED:
        panel_color = hull[loc]
        out = []
        res = program.execute([COLOR_CODES[panel_color]], out)
        hull[loc] = COLOR_CODES[out[0]]
        painted[loc] += 1
        loc, facing = move(loc, facing, out[1])
    return hull, painted
Example #2
0
def scan_area(memory:list, x_fit, y_fit, start_pos=None) -> Union[list, int]:
    program = IntcodeComputer(memory)
    affected = 0
    positions = [start_pos] if start_pos else [(0,0)]
    visited = set()
    while positions:
        rx, ry = positions.pop()
        if (rx, ry) in visited:
            continue
        visited.add((rx, ry))
        in_beam(program, rx, ry)

        if in_beam(program, rx, ry):    
            lx = rx - (x_fit-1)
            ly = ry + (y_fit-1)
            if lx >= 0 and ly >= 0:
                if in_beam(program, lx, ly):
                    break
            positions += [(rx, ry+1), (rx+1, ry)]
    return (lx, ry)
Example #3
0
def run_game(memory:list) -> list:
    program = IntcodeComputer(memory)
    out = []
    program.execute(deque(), out)
    return [out[i:i + 3] for i in range(0, len(out), 3)]
Example #4
0
def run_ascii_program(memory: list) -> list:
    program = IntcodeComputer(memory)
    out = []
    program.execute([], out)
    return list(map(chr, out))
Example #5
0
def BOOST_program(memory: list) -> int:
    program = IntcodeComputer(memory)
    out = []
    res = program.execute(deque([2]), out)
    return out.pop()