예제 #1
0
def get_linear_system_output(phase_settings, memory):
    last_output = 0
    for phase_setting in phase_settings:
        inputs = [phase_setting, last_output]
        intcode_computer = IntcodeComputer(memory, inputs)
        intcode_computer.run()
        last_output = intcode_computer.pop_last_output()

    return last_output
예제 #2
0
from intcode_computer import IntcodeComputer

with open('input.txt', 'r') as f:
    origin_memory = [int(x) for x in f.readline().split(',')]

# Part 1
computer = IntcodeComputer(origin_memory, [1])
computer.run()
print(computer.pop_last_output())

# Part 2
computer = IntcodeComputer(origin_memory, [2])
computer.run()
print(computer.pop_last_output())
예제 #3
0
from intcode_computer import IntcodeComputer

with open('input.txt', 'r') as f:
    origin_memory = [
        int(x) for x in f.readline().split(',')
    ]

# Part 1
inputs = [1]
part1_intcode_computer = IntcodeComputer(origin_memory, inputs)
part1_intcode_computer.run()
print(part1_intcode_computer.pop_last_output())

# Part 2
inputs = [5]
part2_intcode_computer = IntcodeComputer(origin_memory, inputs)
part2_intcode_computer.run()
print(part2_intcode_computer.pop_last_output())
예제 #4
0
def is_being_pulled(x, y):
    intcode_computer = IntcodeComputer(origin_memory, [x, y])
    intcode_computer.run()
    return intcode_computer.pop_last_output() == 1
예제 #5
0
def is_being_pulled(x, y):
    intcode_computer = IntcodeComputer(origin_memory, [x, y])
    intcode_computer.run()
    return intcode_computer.pop_last_output() == 1


SHIP_SIZE = 100

# Part 1
count = 0
for y in range(50):
    for x in range(50):
        intcode_computer = IntcodeComputer(origin_memory, [x, y])
        intcode_computer.run()
        count += intcode_computer.pop_last_output()

# Part 2
y = 0
x = 0
while True:
    # Find first x in row being pulled. Jump forward in increments of 10, then back up in increments of 1.
    while x < y:
        if is_being_pulled(x, y):
            break
        x += 1

    other_x = x + (SHIP_SIZE - 1)
    other_y = y - (SHIP_SIZE - 1)
    if is_being_pulled(other_x, other_y):
        break
예제 #6
0
def run_test(memory, input):
    computer = IntcodeComputer(memory, input)
    computer.run()
    print('Input: {}, Output: {}'.format(input, computer.pop_last_output()))