예제 #1
0
def main():
    # read input
    puzzle_input = get_input('day7_input.txt')

    # determine combinations of phase settings
    phase_settings = get_permutations(0,4)

    # test each set of phase settings, collecting output numbers
    outputs = []
    for phase_setting in phase_settings:
        output = calculate_output(phase_setting, puzzle_input)
        outputs.append(output)

    # print max output number
    print(max(outputs))
예제 #2
0
def main():
    # read input
    puzzle_input = get_input('day9_input.txt')

    # create intcode computer
    comp = IntcodeComp(puzzle_input, 1)

    # run intcode computer
    print('BOOST keycode:')
    comp.compute()

    # create a new intcode computer for part 2 with input value 2
    comp2 = IntcodeComp(puzzle_input, 2)

    # run this intcode computer
    print('Distress signal coordinates:')
    comp2.compute()
예제 #3
0
def main():
    # read input
    intcode = get_input('input.txt')

    # start IntCode computer
    comp = IntcodeComp(intcode)

    # get maze
    maze = np.zeros((50, 50))
    maze = get_maze(comp, [startX, startY], maze)


    # plt.matshow(maze)
    # plt.show()

    # solve maze
    solved = solve_maze(maze)

    plt.matshow(correctPath)
    plt.show()
예제 #4
0
def main():
    # parse input
    input_code = get_input('input.txt')

    # initialize game board
    board = BrickBreaker()

    # initalize intcode computer
    computer = IntcodeComp(input_code)

    # run computer and get outputs
    outputs = computer.compute()

    # slice outputs into sets of three, adding a tile id for each set
    for x, y, tile_id in chunks(outputs, 3):
        board.mark_tile(x, y, tile_id)

    # print the number of block tiles (tile_id = 2)
    print(board.get_tile_count(2))

    # display board
    board.display()
예제 #5
0
def main():
    # read input
    puzzle_input = get_input('input.txt')

    # create hull painter
    painter = Painter()

    # create intcode computer
    comp = IntcodeComp(puzzle_input)

    # run the computer and painter
    while True:
        # input the current color to get color, turn, stop
        color, turn, stop = comp.compute(input_signal=painter.get_current_color())
        # if computer is stopped, stop
        if stop:
            break
        # otherwise paint and move based on computer's directions
        painter.paint(color)
        painter.move(turn)

    # print the number of panels painted at least once
    print(painter.get_count())
예제 #6
0
def main():
    # parse input
    input_code = get_input('input.txt')

    # play for free by setting memory address 0 to 2
    input_code[0] = 2

    # initialize game board
    board = BrickBreaker()

    # initalize intcode computer
    computer = IntcodeComp(input_code)

    # initialize joystic in neutral position
    joystick = 0

    while True:
        # board.display()

        # run computer and get outputs
        outputs = computer.compute(input_signal=joystick)

        for x, y, tile_id in chunks(outputs, 3):
            if x != -1:
                board.mark_tile(x, y, tile_id)
            elif x == -1 and y == 0:
                board.set_score(tile_id)

        joystick = board.get_joystick()

        # if no more blocks, break
        if board.get_tile_count(2) == 0:
            break

    # print the score
    print(board.score)