Esempio n. 1
0
def do_the_thing(content):
    raw_program = list(map(lambda x: int(x), content.split(',')))
    raw_program[0] = 2
    p = IntCode(raw_program)
    main_program = "A,B,A,C,B,A,C,B,A,C\n"
    function_A = "L,6,L,4,R,12\n"
    function_B = "L,6,R,12,R,12,L,8\n"
    function_C = "L,6,L,10,L,10,L,6\n"
    print_output = "n\n"
    p.inputs += [ord(c) for c in list(main_program)]
    p.inputs += [ord(c) for c in list(function_A)]
    p.inputs += [ord(c) for c in list(function_B)]
    p.inputs += [ord(c) for c in list(function_C)]
    p.inputs += [ord(c) for c in list(print_output)]
    p.run_out()

    render_image(p.outputs)

    return p.outputs[-1]
Esempio n. 2
0
def do_the_thing(content):
    raw_program = list(map(lambda x: int(x), content.split(',')))
    p = IntCode(raw_program)
    p.run_out()

    render_image(p.outputs)
    positions = convert_image_to_pos_data(p.outputs)

    alignment_parameters = []
    for position, char in positions.items():
        top_char = get_char_code(positions, position, -1, 0)
        bottom_char = get_char_code(positions, position, 1, 0)
        left_char = get_char_code(positions, position, 0, -1)
        right_char = get_char_code(positions, position, 0, 1)
        if top_char == bottom_char == left_char == right_char == char == 35:
            print(position)
            alignment_parameter = position[0] * position[1]
            alignment_parameters.append(alignment_parameter)

    return sum(alignment_parameters)
Esempio n. 3
0
def run_program(string_program, input):
    raw_program = list(map(lambda x: int(x), string_program.split(',')))
    p = IntCode(raw_program)
    return p.run_out(input)