Exemple #1
0
from intcode import IntCodeComputer
import logging
import sys

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
if __name__ == "__main__":
    p = [
        109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0,
        99
    ]
    c = IntCodeComputer(p)
    assert (c.run_no_interrupt() == p)

    c = IntCodeComputer([1102, 34915192, 34915192, 7, 4, 7, 99, 0])
    assert (len(str(c.run_no_interrupt()[0])) == 16)

    c = IntCodeComputer([104, 1125899906842624, 99])
    assert (c.run_no_interrupt()[0] == 1125899906842624)

    program = list(map(int, open('inputs/day9.txt').read().split(',')))

    logger.info("Running BOOST test mode")
    c = IntCodeComputer(program, [1])
    c.run_no_interrupt()
    print("BOOST Keycode", c.outputs[0])

    logger.info("Running BOOST sensor mode")
    c = IntCodeComputer(program, [2])
    c.run_no_interrupt()
    print("BOOST coordinates", c.outputs[0])
Exemple #2
0
            if tile[0] == -1:
                score = tile[2]
            if tile[2] == 4:
                ball_pos = tile[-3:]
            if tile[2] == 3:
                paddle_pos = tile[:2]
        except InputInterrupt:
            if show:
                render(tiles)
            c.inputs.append(cmp(ball_pos[0], paddle_pos[0]))

    return score


if __name__ == "__main__":
    program = list(map(int, open('inputs/day13.txt').read().split(',')))

    c = IntCodeComputer(program)

    # part 1
    output = list(chunks(c.run_no_interrupt(), 3))
    tile_counts = Counter([x[2] for x in output])
    print(", ".join(f"{tiles_icons[k]} : {v}" for k, v in tile_counts.items()))

    free_play = [2] + program[1:]
    c = IntCodeComputer(free_play)

    score = play(c)
    print("Final Score: ", score)
Exemple #3
0
        try:
            code.append(ord(x))
        except:
            code.append(int(x))
        code.append(ord(','))
    # replace last comma with new line
    code[-1] = ord("\n")
    return code


if __name__ == "__main__":
    program = list(map(int, open('inputs/day17.txt').read().split(',')))

    c = IntCodeComputer(program)

    initial_map = c.run_no_interrupt()
    amap, bot_position = arrayToMap(initial_map)
    intersections = findIntersections(amap)

    print("Alignment", sum(x * y for x, y in intersections))

    main = "C,A,A,B,B,C,C,A,A,B"
    A = "R,12,R,4,L,12"
    B = "R,12,R,4,L,6,L,8,L,8"
    C = "L,12,R,4,R,4"
    display = "y"

    codes = list(map(str_to_incode, [main, A, B, C, display]))

    c2 = IntCodeComputer([2] + program[1:])
    loop = 0