Esempio n. 1
0
def solve_second_part(p, cmds):
    p[0] = 2

    c = IntComputer(p)

    print(cmds)
    c.inputs = [ord(a) for a in cmds] + [10, ord('n'), 10]
    print(c.inputs)

    _map = ""
    halted = False
    while not halted:
        if c.pause:
            c.continue_program()
        else:
            c.run_program()

        if len(c.outputs) > 0:
            v = c.outputs.pop()
            if v < 256:
                _map += chr(v)

        if c.halted:
            halted = True

    print(_map)
    print(v)
    print(c.outputs)
Esempio n. 2
0
def run_springscript(p, script):
    c = IntComputer(p)

    c.inputs = [ord(a) for a in script]
    print(c.inputs)

    _map = ""
    halted = False
    while not halted:
        if c.pause:
            c.continue_program()
        else:
            c.run_program()

        if len(c.outputs) > 0:
            v = c.outputs.pop()
            if v < 256:
                _map += chr(v)

        if c.halted:
            halted = True

    print(_map)
    print(v)

    return v
Esempio n. 3
0
def tractor_beam(x, y, p):
    c = IntComputer(p)

    c.inputs = [x, y]

    result = 0
    halted = False
    while not halted:
        if c.pause:
            c.continue_program()
        else:
            c.run_program()

        if len(c.outputs) > 0:
            result = c.outputs.pop()

        if c.halted:
            halted = True
    return result