Example #1
0
def run():
    instructions = open_file("input_day07.txt")

    best = 0
    for perm in itertools.permutations([5, 6, 7, 8, 9]):
        machines = []
        machine_io = []
        for n in range(5):
            io = MachineIO(machine_io, n, perm[n])
            machine_io.append(io)
            machines.append(
                IntCodeMachine(instructions.copy(), io.oninput, io.onoutput))

        # Kick off signal, since the last machine feeds into the first, we put it there
        machine_io[-1].output.append(0)

        while not (all(machine.halted for machine in machines)):
            for machine, io in zip(machines, machine_io):
                while not machine.halted:
                    machine.step()
                    if io.output:
                        break

        best = max(machine_io[-1].max_output, best)
    print(best)
Example #2
0
def run():
    memory = open_file("input_day17.txt")
    memory[0] = 2
    machine = IntCodeMachine(memory, onread=oninput, onwrite=onoutput)
    machine.run()
    for line in scaffold:
        print(''.join(line))
Example #3
0
def run():
    memory = open_file("input_day17.txt")
    machine = IntCodeMachine(memory, None, onwrite=onoutput)
    machine.run()

    for line in scaffold:
        print(''.join(line))

    print(intersections())
Example #4
0
def run():
    memory = open_file("input_day23.txt")
    nat = NAT()
    computers, queues = initialize_computers(memory, 50, nat)

    while True:
        for n in range(50):
            computers[n].step()
            if all(queues[n].idle for n in range(50)):
                nat.release(queues[0])
Example #5
0
def run():
    memory = open_file("input_day19.txt")
    for y in range(max_y):
        for x in range(max_x):
            lst = [y, x]
            print(lst)
            machine = IntCodeMachine(memory.copy(), lst.pop,
                                     lambda v: update_grid(x, y, v))
            machine.run()

    for line in grid:
        print(''.join(str(x) for x in line))

    print(sum(sum(line) for line in grid))
Example #6
0
def run():
    best, best_perm = 0, None
    for perm in itertools.permutations([0, 1, 2, 3, 4]):
        result = [0]
        for phase in perm:
            input_list = [result.pop(), phase]
            instructions = open_file("input_day07.txt")
            IntCodeMachine(instructions, input_list.pop, result.append).run()

        if result[-1] > best:
            best, best_perm = result[-1], perm
            best_perm = perm

    print(best, best_perm)
Example #7
0
def run():
    memory = open_file("input_day21.txt")
    machine = IntCodeMachine(memory, onread=oninput, onwrite=onoutput)
    machine.run()
Example #8
0
def run():
    memory = open_file("input_day23.txt")
    computers = initialize_computers(memory, 50)
    while True:
        for n in range(50):
            computers[n].step()
Example #9
0
def run():
    memory = open_file("input_day25.txt")
    machine = IntCodeMachine(memory, oninput, onoutput)
    machine.run()
Example #10
0
def run():
    memory = open_file("input_day19.txt")
    x, y = loop(memory)
    print(x, y, 10000 * x + y)