Exemplo n.º 1
0
def run():
    i = IntCode([104, 1125899906842624,
                 99])  # Works cus python handles big nums
    i.compile()
    print(i.output[-1])

    i = IntCode([1102, 34915192, 34915192, 7, 4, 7, 99, 0])
    i.input_signal(1)
    print(i.output[-1])

    i = IntCode([
        109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0,
        99
    ])
    i.input_signal(1)
    print(i.output)  # Quine

    i = IntCode(parseFile('day9.txt'))
    i.input_signal(1)
    print(i.output)

    i = IntCode(parseFile('day9.txt'))
    i.input_signal(2)
    print(i.output)
    return
Exemplo n.º 2
0
def run():
    image = [[' ' for x in range(47)] for y in range(47)]
    program = IntCode(parseFile('day17.txt'))
    program.compile()

    x = y = 0
    for char in program.output:
        if char == 35:
            image[x][y] = "#"
            x += 1
        elif char == 46:
            image[x][y] = "."
            x += 1
        elif char == 10:
            print("\n")
            y += 1
            x = 0
    for line in image:
        print("".join(line))
    sum = 0
    for x in range(47):
        for y in range(47):
            try:
                if (image[x][y] == "#" and image[x + 1][y] == "#"
                        and image[x - 1][y] == "#" and image[x][y + 1] == "#"
                        and image[x][y - 1] == "#"):
                    sum += x * y
            except (IndexError):
                pass
    print(sum)
    return
Exemplo n.º 3
0
def run():
    global dir_dict
    # directions = ['north','south','west','east']

    visited = {(0, 0): " "}
    program = IntCode(parseFile('day15.txt'))
    # Initialize heap to store list
    h = list()
    heapq.heapify(h)

    # Storage structure -> list [tuple(int x,int y) , class:IntCode program, steps:int, direction:str]
    # Initialize start
    for dir in dir_dict.keys():
        heapq.heappush(h, [updatePos(0, 0, dir), program, 0, dir])

    while len(h):
        (x, y), prog, steps, dir = heapq.heappop(h)
        prog.input_signal(dir_dict[dir].get('input'))
        status = prog.output.pop(0)
        dupe = prog.duplicate()  # Create new duplicated instance
        if status == 0:
            visited[(x, y)] = '█'
        elif status == 1:
            visited[(x, y)] = " "
            for dir in dir_dict.keys():
                x, y = updatePos(x, y, dir)
                if (x, y) not in visited.keys():
                    heapq.heappush(h, [(x, y), dupe, steps + 1, dir])
        elif status == 2:
            visited[(x, y)] = "0"
            return (steps)
Exemplo n.º 4
0
def run():
    program = IntCode(parseFile('day13.txt'))
    # every three output instructions specify the x position (distance from the left), y position (distance from the top), and tile id. The tile id is
    # 0 is an empty tile. No game object appears in this tile.
    # 1 is a wall tile. Walls are indestructible barriers.
    # 2 is a block tile. Blocks can be broken by the ball.
    # 3 is a horizontal paddle tile. The paddle is indestructible.
    # 4 is a ball tile. The ball moves diagonally and bounces off objects

    # while not program.terminate:
    #     break
    program.compile()

    return
Exemplo n.º 5
0
def run():
    sum = 0
    image = [[' ' for x in range(50)] for y in range(50)]
    for x in range(50):
        for y in range(50):
            program = IntCode(parseFile('day19.txt'))
            program.input_signal(x)
            program.input_signal(y)
            if program.output[-1] == 1:
                image[x][y] = "#"
            sum += program.output[-1]
    for line in image:
        print("".join(line))
    print(sum)
    return
Exemplo n.º 6
0
def run(color):
    init_dir = 'north'
    dir_dict = {
        'north': [0, 1],
        'south': [0, -1],
        'west': [-1, 0],
        'east': [1, 0],
    }
    x = y = 0
    dict = {(0, 0): color}
    program = IntCode(parseFile('day11.txt'))
    while not program.terminate:
        program.input_signal(dict[(x, y)] if (x, y) in dict else 0)  # 1 or 0
        dict[(x, y)] = program.output.pop(0)
        direction = 'left' if program.output.pop(0) == 0 else 'right'
        init_dir = facing(init_dir, direction)
        x = x + dir_dict[init_dir][0]
        y = y + dir_dict[init_dir][1]
    print(len(dict))
    return dict
Exemplo n.º 7
0
def droneReport(x, y):
    program = IntCode(parseFile('day19.txt'))
    program.input_signal(x)
    program.input_signal(y)
    return program.output[-1]