コード例 #1
0
ファイル: solution.py プロジェクト: ccharles/AdventCode
def run_the_magic_program(input_sequence, noun, verb):
    # create a copy of input_sequence to make sure we don't change the
    # original one
    input_sequence_copy = input_sequence.copy()
    input_sequence_copy[1] = noun
    input_sequence_copy[2] = verb

    command_invoker = IntcodeComputer(program=input_sequence_copy)
    command_invoker.run_program()
    return command_invoker.get_memory_state()[0]
コード例 #2
0
def solution():
    from pathlib import Path
    input_file = Path(INPUT_FILE)
    # parse the sequence of commands and replace two elements with values
    # according to the task
    program = parse_program(input_file)
    program[1] = 12
    program[2] = 2
    # do the calculation
    computer = IntcodeComputer(program=program)
    computer.run_program()
    result = computer.get_memory_state()
    return result[0]