コード例 #1
0
 def __init__(self, hull, program, start_on_white=False):
     self.hull = hull
     self.x = 0
     self.y = 0
     if start_on_white:
         self.hull.panels[(0, 0)].color = WHITE
     self.direction = 'Up'
     self.brain = intcode.IntcodeComputer(program, [])
コード例 #2
0
            path = networkx.shortest_path(self.graph, tile, t)
            length = len(path)
            if length > furthest:
                furthest = length
        return furthest


def plot_map(walls, oxygen, path):
    x, y = zip(*[[w.x, w.y] for w in walls.values()])
    plt.plot(x, y, 'x')
    plt.plot(oxygen[0], oxygen[1], 'o')
    plt.plot(0, 0, '+')
    pathx, pathy = zip(*path)
    plt.plot(pathx, pathy)
    plt.legend(['Walls', 'oxygen', 'origin', 'path'])
    plt.show()


if __name__ == "__main__":
    computer = intcode.IntcodeComputer(
        intcode.read_intcode_input_file('input.txt'), [])
    repair_droid = RepairDroid(computer)
    oxygen = repair_droid.map_corridors()
    repair_droid.generate_graph(oxygen)
    # networkx.draw(repair_droid.graph)
    path_to_oxygen = repair_droid.path_to_oxygen(oxygen)
    print("Distance to oxygen = ", len(path_to_oxygen) - 1)
    minutes = repair_droid.fill_oxygen(oxygen) - 1
    print("mintutes to fill oxygen : ", minutes)
    plot_map(repair_droid.walls, oxygen, path_to_oxygen)
    plt.show()
コード例 #3
0
import intcode
from enum import IntEnum


class Direction(IntEnum):
    UP = 0
    RIGHT = 1
    DOWN = 2
    LEFT = 3
    total = 4


with open('day11-input.txt', 'r') as f:
    instr_list = [int(w) for w in f.readline().split(',')]

comp = intcode.IntcodeComputer(instr_list)

wall = np.zeros((200, 200), np.uint8)
_wall = np.zeros((200, 200), np.bool)
curr_coord = [100, 100]
curr_direction = Direction.UP

import sys
if len(sys.argv) == 1 or sys.argv[1] == '1':
    print('Part 1')
    pass
elif sys.argv[1] == '2':
    # Part 2
    print('Part 2')
    wall[tuple(curr_coord)] = 1
else:
コード例 #4
0
 def __init__(self, program):
     self.program = program
     self.computer = intcode.IntcodeComputer(program, [],
                                             input_function=self.next_input)
     self.tiles = {}
コード例 #5
0
import intcode

# Part 1
with open('day05-input.txt', 'r') as f:
    instr_list = [int(w) for w in f.readline().split(',')]

print('============== Part 1 ==============')
comp = intcode.IntcodeComputer(instr_list, input_list=[
    1,
])
print(comp.run())

print('============== Part 2 ==============')
print('test')
instr_list_test_0 = [
    3, 21, 1008, 21, 8, 20, 1005, 20, 22, 107, 8, 21, 20, 1006, 20, 31, 1106,
    0, 36, 98, 0, 0, 1002, 21, 125, 20, 4, 20, 1105, 1, 46, 104, 999, 1105, 1,
    46, 1101, 1000, 1, 20, 4, 20, 1105, 1, 46, 98, 99
]
comp = intcode.IntcodeComputer(instr_list_test_0, input_list=[
    7,
])
print(comp.run(), 'expect 999')

comp = intcode.IntcodeComputer(instr_list_test_0, input_list=[
    8,
])
print(comp.run(), 'expect 1000')

comp = intcode.IntcodeComputer(instr_list_test_0, input_list=[
    9,
コード例 #6
0
import intcode

with open('day09-input.txt', 'r') as f:
    instr_list = [int(w) for w in f.readline().split(',')]

comp = intcode.IntcodeComputer(instr_list, [
    1,
])
print('Part 1', comp.run())

comp = intcode.IntcodeComputer(instr_list, [
    2,
])
print('Part 2', comp.run())
コード例 #7
0
    i = 2
    num_blocks = 0
    while i < len(outputs):
        if outputs[i] == 2:
            num_blocks += 1
        i += 3

    return num_blocks


og_intcode = []
with open('input.txt', 'r') as problem_input:
    for i, line in enumerate(problem_input):
        og_intcode = [int(val) for val in line.split(",")]

intcode_comp = intcode.IntcodeComputer(list(og_intcode), 0)

outputs = []
while not intcode_comp.halted:
    outputs.append(intcode_comp.run_intcode(0))

print(partOne(outputs))

# Part Two

comp2 = intcode.IntcodeComputer(list(og_intcode), 0)
comp2.intcode[0] = 2

points = 0
ball_x = paddle_x = 0
input_val = 0