Exemplo n.º 1
0
    corner = {}
    while True:
        beam = is_tractor_beam(x0, y)
        if beam:
            x1 = x0 + w - 1
            if is_tractor_beam(x1, y):
                while True:
                    x1 += 1
                    if not is_tractor_beam(x1, y):
                        break
                corner[y] = (x0, x1 - 1)
                miny, y1 = min(corner.keys()), max(corner.keys())
                if y1 - miny >= h:
                    y0 = y1 - h + 1
                    width = corner.get(y0, (0, 0))[1] - corner[y1][0]
                    # print(x0, y0, ", width:", width)
                    if width >= w - 1:
                        return corner[y0][1] - w + 1, y0
            y += 1
        else:
            # assuming beam on next row always startx at least 1 block to the right
            x0 += 1


program = init(open("day19-input.txt", "r").read())

print(tractor_beam_area(50, 50))

x, y = tractor_beam_fitting(100, 100)
print(x * 10000 + y)
Exemplo n.º 2
0
from intcode_computer import init, parse
from copy import deepcopy


def part1(inputs):
    init_state = deepcopy(inputs)
    init_state["memory"][1], init_state["memory"][2] = 12, 2
    return parse(init_state)["memory"][0]


def part2(inputs):
    for i in range(100):
        for j in range(100):
            init_state = deepcopy(inputs)
            init_state["memory"][1], init_state["memory"][2] = i, j
            if parse(init_state)["memory"][0] == 19690720:
                return 100 * i + j


init_state = init(open("day2-input.txt", "r").read())

print(part1(init_state))
print(part2(init_state))
Exemplo n.º 3
0
from intcode_computer import init, parse
from copy import deepcopy

remote_control_program = init(open("day15-input.txt", "r").read())
Exemplo n.º 4
0
        for i in range(0, len(outputs), 3):
            x, y, t = outputs[i:i + 3]
            if x == -1 and y == 0:
                score = t
            elif t == 0:
                len_blanks += 1
            elif t == 3:
                paddle = x
            elif t == 4:
                ball = x
        if num_blanks == len_blanks:
            return score
        num_blanks = len_blanks
        if paddle < ball:
            joystick = 1
        elif paddle > ball:
            joystick = -1
        else:
            joystick = 0
        if visualise:
            print_board([outputs[x:x + 3] for x in range(0, len(outputs), 3)])


game = init(open("day13-input.txt", "r").read())

outputs = parse(deepcopy(game))["outputs"]
draw_instructions = [outputs[x:x + 3] for x in range(0, len(outputs), 3)]
print(len([None for _, _, t in draw_instructions if t == 2]))

print(play(deepcopy(game)))
Exemplo n.º 5
0
from intcode_computer import init, parse
from copy import deepcopy

init_state = init(open("day5-input.txt").read())

part1_init = deepcopy(init_state)
part1_init["inputs"] = [1]
print(parse(part1_init)["outputs"])

part2_init = deepcopy(init_state)
part2_init["inputs"] = [5]
print(parse(part2_init)["outputs"])