Ejemplo n.º 1
0
def run_with_screen(program):
    computer = Computer(program)
    pad = 0
    ball = 0
    done = False
    score = 0

    while not done:
        computer.next_input = lambda: joystick(pad, ball)

        computer.iterate()
        x = computer.output

        computer.iterate()
        y = computer.output

        done = computer.iterate()
        tile = computer.output

        if tile == 4:
            ball = x
        if tile == 3:
            pad = x

        if x == -1 and y == 0:
            score = tile

        if done:
            return score
Ejemplo n.º 2
0
def run_to_output(program):
    outputs = []
    computer = Computer(program)
    done = False

    while not done:
        done = computer.iterate()
        if not done:
            outputs.append(computer.output)

    return outputs
Ejemplo n.º 3
0
def run(inputs):
    program = parse_file('game.intcode')
    c = Computer(program, inputs)

    o = ''
    while True:
        done = c.iterate()
        if done:
            break
        else:
            print(chr(c.output), end='')
            #o += chr(c.output)
    return o
Ejemplo n.º 4
0
p = ','.join(str(s) for s in path)
print('Path:', p)

program = parse_file("input.intcode")
program[0] = 2
computer = Computer(program)

with open('robot_path.txt') as f:
    inputs = []
    for line in f.readlines():
        for c in line:
            inputs.append(ord(c))


class inputter:
    def __init__(self, inputs):
        self.inputs = inputs

    def next(self):
        n = self.inputs.pop(0)
        return n


inp = inputter(inputs)
computer.next_input = inp.next
done = False
while not done:
    done = computer.iterate()

print("Part 2:", computer.output)
Ejemplo n.º 5
0
def check(x, y):
    inputs = inputter([x, y])
    computer = Computer(parse_file('input.intcode'))
    computer.next_input = inputs.next
    computer.iterate()
    return computer.output == 1