示例#1
0
        print()

def find_angle_limits(locs):
    max_angle = min_angle = math.atan2(1, 1)

    for x, y in locs:
        if x == 0 and y == 0:
            continue
        angle = math.atan2(x, y)
        max_angle = max(max_angle, angle)
        min_angle = min(min_angle, angle)

    print("Max:", max_angle)
    print("Min:", min_angle)

code = IntCode.load_from_file('../data/input19')

# part 1

def part1():
    affected_locs = []
    map = []
    for x in range(50):
        row = []
        for y in range(50):
            outputs = code.copy().run(inputs=[x, y], print_outputs=False)
            if outputs[0] == 1:
                affected_locs.append((x, y))

            row.extend(outputs)
        map.append(row)
示例#2
0
from intcode import IntCode

orig_code = IntCode.load_from_file('../data/input11')

def update_direction(d, turn, curr_square):
    if turn == 0:
        d = (d - 1) % 4
    else:
        d = (d + 1) % 4

    if d == 0:
        curr_square = (curr_square[0]-1, curr_square[1])
    elif d == 1:
        curr_square = (curr_square[0], curr_square[1]-1)
    elif d == 2:
        curr_square = (curr_square[0]+1, curr_square[1])
    elif d == 3:
        curr_square = (curr_square[0], curr_square[1]+1)

    return d, curr_square

colors = {}
curr_square = (0, 0)
direction = 0

code = orig_code.copy()
while not code.terminated:
    # get color of current square
    inputs = [colors.get(curr_square, 0)]
    
    outputs = code.run(inputs=inputs, print_outputs=False)