コード例 #1
0
ファイル: part02.py プロジェクト: Berteun/adventofcode2019
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)
コード例 #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))
コード例 #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())
コード例 #4
0
ファイル: part02.py プロジェクト: Berteun/adventofcode2019
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])
コード例 #5
0
ファイル: part01.py プロジェクト: Berteun/adventofcode2019
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))
コード例 #6
0
ファイル: part01.py プロジェクト: Berteun/adventofcode2019
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)
コード例 #7
0
def run():
    memory = open_file("input_day21.txt")
    machine = IntCodeMachine(memory, onread=oninput, onwrite=onoutput)
    machine.run()
コード例 #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()
コード例 #9
0
ファイル: part01.py プロジェクト: Berteun/adventofcode2019
def run():
    memory = open_file("input_day25.txt")
    machine = IntCodeMachine(memory, oninput, onoutput)
    machine.run()
コード例 #10
0
ファイル: part02.py プロジェクト: Berteun/adventofcode2019
def run():
    memory = open_file("input_day19.txt")
    x, y = loop(memory)
    print(x, y, 10000 * x + y)