コード例 #1
0
    #print('Sending: ', cmd)
    for char in cmd:
        program.input.put(ord(char))
    program.input.put(10)


def print_output():
    while not program.output.empty():
        read = program.output.get()
        if read < 256:
            print(chr(read), end='')
        else:
            print(f'\nResult: {read}')


with open("input_day25.txt", "r") as input_file:
    program_code = list(map(int, input_file.readline().strip(" ").split(",")))

    program = intcode.Program(0, program_code, Queue())
    program_thread = threading.Thread(target=program.run)
    program_thread.start()

    while program_thread.is_alive():
        sleep(0.1)
        print_output()
        if not program_thread.is_alive():
            break
        user_input = input('')
        send_input(user_input)

    print('End')
コード例 #2
0
from collections import namedtuple
import threading
from queue import Queue

if __name__ == '__main__':
    with open("input_day23.txt", "r") as input_file:
        program_code = list(
            map(int,
                input_file.readline().strip(" ").split(",")))

    print(f'Initializing')
    nics = []
    nic_threads = []
    for nic in range(50):
        nics.append(
            intcode.Program(nic, program_code, Queue(), special_mode_23=True))
        nics[nic].input.put(nic)

    print(f'Starting')
    for nic in range(50):
        nic_threads.append(threading.Thread(target=nics[nic].run))
        nic_threads[nic].start()

    print(f'Starting message broker')
    NAT_y_values = set()
    latest_NAT = None
    while True:
        idle = True
        for nic in range(50):
            if not nics[nic].output.empty():
                idle = False
コード例 #3
0
def get_output():
    while not program.output.empty():
        read = program.output.get()
        if read < 256:
            print(chr(read), end='')
        else:
            print(f'\nResult: {read}')


if __name__ == '__main__':
    with open("input_day21.txt", "r") as input_file:
        program_code = list(
            map(int,
                input_file.readline().strip(" ").split(",")))

    program = intcode.Program(0, program_code)
    #program.print()

    program_thread = threading.Thread(target=program.run)
    program_thread.start()

    sleep(1)
    get_output()
    send_input('OR E J')
    send_input('OR H J')
    send_input('NOT C T')
    send_input('AND T J')

    send_input('NOT B T')
    send_input('OR T J')
コード例 #4
0
def probe(x, y):
    program = intcode.Program(0, program_code)
    program.input.put(x)
    program.input.put(y)
    program.run()
    return program.output.get()