예제 #1
0
파일: day_7.py 프로젝트: jdpatt/AoC
class Amplifier:
    def __init__(self, program, inputs=None):
        self.computer = IntCodeComputer(program)
        if inputs:
            self.computer.input_register = inputs

    def run(self):
        self.computer.run()

    def is_running(self):
        return self.computer.running

    def set_input(self, obj):
        self.computer.input_register = obj

    def set_output(self, obj):
        self.computer.output_register = obj
예제 #2
0
파일: day_9.py 프로젝트: jdpatt/AoC
def test_program_1():
    computer = IntCodeComputer([
        109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0,
        99
    ])
    computer.run()
    assert computer.output_results() == [
        109,
        1,
        204,
        -1,
        1001,
        100,
        1,
        100,
        1008,
        100,
        16,
        101,
        1006,
        101,
        0,
        99,
    ]
예제 #3
0
파일: day_7.py 프로젝트: jdpatt/AoC
 def __init__(self, program, inputs=None):
     self.computer = IntCodeComputer(program)
     if inputs:
         self.computer.input_register = inputs
예제 #4
0
파일: day_9.py 프로젝트: jdpatt/AoC
def test_program_3():
    computer = IntCodeComputer([104, 1125899906842624, 99])
    computer.push(1)
    computer.run()
    assert computer.output_results() == [1125899906842624]
예제 #5
0
파일: day_9.py 프로젝트: jdpatt/AoC
def test_program_2():
    computer = IntCodeComputer([1102, 34915192, 34915192, 7, 4, 7, 99, 0])
    computer.push(1)
    computer.run()
    assert computer.output_results() == [1219070632396864]
예제 #6
0
파일: day_9.py 프로젝트: jdpatt/AoC
"""Advent of Code 2019 Day 9"""
from shared.common import get_input
from shared.intcode_computer import IntCodeComputer

if __name__ == "__main__":
    BOOST_PROGRAM = [int(x) for x in get_input("input9.txt").split(",")]
    computer = IntCodeComputer(BOOST_PROGRAM.copy())
    computer.push(1)
    computer.run()
    print(f"BOOST KeyCode: {computer.output_results()}")
    del computer

    computer = IntCodeComputer(BOOST_PROGRAM.copy())
    computer.push(2)
    computer.run()
    print(f"Coordinates of the Distress Signal: {computer.output_results()}")


def test_program_1():
    computer = IntCodeComputer([
        109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0,
        99
    ])
    computer.run()
    assert computer.output_results() == [
        109,
        1,
        204,
        -1,
        1001,
        100,
예제 #7
0
파일: day_2.py 프로젝트: jdpatt/AoC
"""Advent of Code 2019 Day 2"""
from shared.common import get_and_transform_input
from shared.intcode_computer import IntCodeComputer

if __name__ == "__main__":
    PROGRAM = [
        int(x) for x in get_and_transform_input("input2.txt")[0].split(",")
    ]
    MEMORY = {index: item for index, item in enumerate(PROGRAM)}
    COMPUTER = IntCodeComputer(memory=MEMORY.copy())
    COMPUTER.store(1, 12)
    COMPUTER.store(2, 2)
    print(f"Part 1 after completion: {COMPUTER.run()}")

    print("Part 2")
    for noun in range(100):
        for verb in range(100):
            COMPUTER = IntCodeComputer(memory=MEMORY.copy())
            COMPUTER.store(1, noun)
            COMPUTER.store(2, verb)
            if COMPUTER.run() == 19690720:
                print(f"Noun: {noun} Verb: {verb}")
                print(f"Part 2 Results {100 * noun + verb}")
                break
예제 #8
0
"""Advent of Code 2019 Day 5"""

from shared.common import get_input
from shared.intcode_computer import IntCodeComputer

if __name__ == "__main__":
    PUZZLE = [int(x) for x in get_input("input5.txt").split(",")]
    SHIP_ID = 1
    computer = IntCodeComputer(PUZZLE.copy())
    computer.push(SHIP_ID)
    computer.run()
    print(
        f"Thermal Environment Supervision Terminal Diagnostics: {computer.output_results()}"
    )
    del computer

    # Part 2
    SHIP_ID = 5
    computer = IntCodeComputer(PUZZLE.copy())
    computer.push(SHIP_ID)
    computer.run()
    print(
        f"Thermal Radiator Controller Diagnostics: {computer.output_results()}"
    )