Esempio n. 1
0
def test_day_9_prog_3():
    test_prog = [104, 1125899906842624, 99]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
    assert res is False  # End of program
    assert output[0] == test_prog[1]  # test prog 2 prints a 16 char
Esempio n. 2
0
def test_day_9_prog_2():
    test_prog = [1102, 34915192, 34915192, 7, 4, 7, 99, 0]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
    assert res is False  # End of program
    assert len(str(output[0])) == 16  # test prog 2 prints a 16 char
Esempio n. 3
0
def test_day_5_jump_pos():
    test_prog = [3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
        if res is True:
            ic.next_input = 5
    print(output)
Esempio n. 4
0
def test_day_5_prog_2():
    test_prog = [1002, 4, 3, 4, 33]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
    assert res is False  # End of program
    assert len(output[:-1]) == 0
    test_prog_final = [1002, 4, 3, 4, 99]
    assert ic._state == test_prog_final
Esempio n. 5
0
def test_day_5_equal_to():
    test_prog = [3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    my_input = 5
    ic.next_input = my_input
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
    assert res is False  # End of program
    assert len(output[:-1]) == 1
    assert output[0] == 0
Esempio n. 6
0
def test_day_9_prog_1():
    test_prog = [
        109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0,
        99
    ]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
    assert res is False  # End of program
    assert output[:-1] == test_prog  # test prog 1 prints itself
Esempio n. 7
0
def test_day_3_prog_1():
    test_prog = [1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
    assert res is False  # End of program
    test_prog_final = test_prog.copy()
    test_prog_final[0] = 3500
    test_prog_final[3] = 70
    assert len(output[:-1]) == 0
    assert ic._state == test_prog_final
Esempio n. 8
0
def test_day_5_prog_1():
    test_prog = [3, 0, 4, 0, 99]
    ic = IntcodeComputer(initial_state=test_prog)
    res = True
    output = []
    my_input = 5
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
        if res is True:
            ic.next_input = my_input
    assert res is False  # End of program
    assert len(output[:-1]) == 2
    assert output[0] is True
    assert output[1] == my_input
Esempio n. 9
0
def test_boost_program():
    with open("boost.txt") as input_file:
        input_string = input_file.read()
        boost_program = [int(x) for x in input_string.split(sep=',')]
    ic = IntcodeComputer(initial_state=boost_program)
    ic.next_input = 1
    res = True
    output = []
    while res is not False:
        res = ic.run_computer()
        # print(res)
        output.append(res)
    assert res is False  # End of program
    print(output)
    assert len(output[:-1]) == 1  # Boost should only produce a single integer
    my_correct_res = 3518157894  # for my input, this is what boost should output (when input 1)
    assert output[0] == my_correct_res
Esempio n. 10
0
import sys
sys.path.append("c:\\dev\\git\\personal\\advent2019")
from intcode_computer.intcode_computer import IntcodeComputer

filename = "day02/input"

with open(filename) as file_object:
    initial_data = file_object.readline()

computer = IntcodeComputer("1,1,1,4,99,5,6,0,99")

computer.run()

print(computer.memory)

# for x in range(0, 100):
#     for y in range(0, 100):
#         computer.reset()
#         computer.setMemory(1, x)
#         computer.setMemory(2, y)
#         computer.run()

#         if computer.readMemory(0) == 19690720:
#             print(100 * x + y)
#             break

Esempio n. 11
0
    else:
        return prev_output


def output_function(x, context):
    context.is_running = False
    global prev_output
    # print("Yielding " + str(x))
    prev_output = x


max_result = 0

for p in permutations:
    prev_output = 0
    amps = list(map(lambda x: IntcodeComputer(initial_data), range(0, 5)))
    phases_set = [False, False, False, False, False]

    while (amps[0].get_opcode() != 99):
        for i in range(0, 5):
            amps[i].input_function = input_function
            amps[i].output_function = output_function

        for i in range(0, 5):
            amps[i].run()

    if prev_output > max_result:
        max_result = prev_output

print(max_result)
Esempio n. 12
0
import sys
sys.path.append("d:\\dev\\advent2019")
from intcode_computer.intcode_computer import IntcodeComputer

filename = "day05/input"

with open(filename) as file_object:
    initial_data = file_object.readline()

computer = IntcodeComputer(initial_data)

computer.run()
Esempio n. 13
0
 def __init__(self):
     self.computer = IntcodeComputer()
     self.facing = 0  # In degrees
     self.x = 0
     self.y = 0
Esempio n. 14
0
input_path = "input.txt"
with open(input_path) as input_file:
    input_string = input_file.read()
    intcode_program_list = [int(x) for x in input_string.split(sep=',')]

from intcode_computer.intcode_computer import IntcodeComputer

ic = IntcodeComputer(initial_state=intcode_program_list)

res = True
output = []
while res is not False:
    res = ic.run_computer()
    output.append(res)
    if res is True:
        ic.next_input = 2

print(output)
Esempio n. 15
0
import sys
sys.path.append("d:\\dev\\advent2019")
from intcode_computer.intcode_computer import IntcodeComputer

with open("day07/input") as file_object:
    initial_data = file_object.readline()

with open("day07/permutations") as file_object:
    permutations = list(map(lambda x: list(map(lambda y: int(y), x.split(","))), file_object.readlines()))

print(permutations)

computer = IntcodeComputer(initial_data)

def test_permutation(permutation):
    global prev_result
    prev_result = 0

    for i in permutation:
        inputs = [i, prev_result]
        global z
        z = 0

        def input_method():
            global z
            #print(inputs[z])
            q = inputs[z]
            z += 1
            return q
        
        def output_method(x):
Esempio n. 16
0
import sys
sys.path.append("d:\\dev\\advent2019")
from intcode_computer.intcode_computer import IntcodeComputer

filename = "day09/input"

with open(filename) as file_object:
    program = file_object.readline()

computer = IntcodeComputer(program)

computer.run()