Ejemplo n.º 1
0
 def __init__(self, program):
     self.intcode = comp.IntComp(list(program), debug=False)
     self.n_outputs_seen = 0
     self.hull = {}
     self.painted = {}
     self.direction = 'up'
     self.pos = (0, 0)
     self.minx = 1000
     self.miny = 1000
     self.maxx = 0
     self.maxy = 0
Ejemplo n.º 2
0
def solve_with_input(line, input):
    program = line.replace(' ', '').replace('\n', '').split(',')
    c = comp.IntComp(program, debug=False)
    c.add_input(input)

    # Execute the program in a loop until it provides no more output and reports
    # that is has finished.
    stopped = False
    while not stopped:
        result = c.run(lambda output: print(output))
        if result[0] == comp.IntComp.FINISHED:
            stopped = True
            print('Final result code from program: {}'.format(result[1]))
Ejemplo n.º 3
0
def calculate_thrust(program, phases):

    state = State()

    amps = []

    # Initialize all five amplifiers
    for phase in phases:
        amp = comp.IntComp(list(program))
        amp.add_input(phase)
        amps.append(amp)

    for amp in amps:
        amp.add_input(state.state)
        amp.run(lambda output: state.setState(output))

    return state.state
Ejemplo n.º 4
0
def calculate_thrust_part2(program, phases):

    state = State()

    amps = []

    # Initialize all five amplifiers
    for phase in phases:
        amp = comp.IntComp(list(program))
        amp.add_input(phase)
        amps.append(amp)

    stopped = False
    while not stopped:
        for amp in amps:
            amp.add_input(state.state)  # pass input from last round
            return_code = amp.run(lambda output: state.setState(output))[0]
            if return_code == comp.IntComp.FINISHED:
                stopped = True

    return state.state
Ejemplo n.º 5
0
 def __init__(self, program):
     self.intcode = comp.IntComp(list(program), debug=False)
     self.text = ''
Ejemplo n.º 6
0
 def __init__(self, program, script, interactive=False):
     self.intcode = comp.IntComp(list(program), debug=False)
     self._interactive = interactive
     self._script = script
Ejemplo n.º 7
0
def solve(line):
    program = line.replace(' ', '').replace('\n', '').split(',')
    c = comp.IntComp(program, debug=False)
    while (c.run(lambda output: print(output))[0] != comp.IntComp.FINISHED):
        True
Ejemplo n.º 8
0
 def __init__(self, program):
     self.intcode = comp.IntComp(list(program), debug=False)
     self.row = 0
     self.col = 0
     self.grid = nd.zeros(shape=(33, 45), dtype=object)
     self.dust = 0