Esempio n. 1
0
    def run(self):
        intcode.execute_program(self.program, self.get_input,
                                self.store_output)

        self.win.nodelay(False)
        self.win.addstr(10, 55, "GAME OVER")
        self.win.addstr(11, 50, "(press any key to exit)")
        self.win.getch()

        curses.nocbreak()
        curses.curs_set(True)
        self.stdscr.keypad(False)
        curses.echo()
        curses.endwin()
def main(instructions):
    conf = dict(x_next=True)
    plot = dict()

    for y in range(50):
        for x in range(50):
            program_thread = execute_program(instructions.copy(),
                                             partial(producer, (x, y), conf),
                                             partial(consumer, plot, (x, y)),
                                             True)

            program_thread.join()

    affected = sum(plot.values())
    print(f"there are {affected} points")
def main(instructions):
    data = defaultdict(list)
    temp = defaultdict(list)

    threads = []
    for i in range(50):
        data[i] = [[i]]

        thread = execute_program(instructions.copy(),
                                 partial(producer, data[i]),
                                 partial(consumer, data, temp[i]), False)
        threads.append(thread)

    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()
def main(instructions):
    data = defaultdict(list)
    temp = defaultdict(list)
    data[IDLE] = 0

    threads = [Thread(target=monitor_thread, args=(data, ))]

    for i in range(50):
        data[i] = [[i]]

        thread = execute_program(instructions.copy(),
                                 partial(producer, data, i),
                                 partial(consumer, data, temp[i]), False)
        threads.append(thread)

    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()
Esempio n. 5
0
def main(instructions):
    in_data = list("\n".join([
        "south",
        "west",
        "take fuel cell",
        "west",
        "take easter egg",
        "east",
        "east",
        "north",
        "north",
        "north",
        "east",
        "east",
        "take cake",
        "west",
        "west",
        "south",
        "south",
        "east",
        "take ornament",
        "east",
        "take hologram",
        "east",
        "take dark matter",
        "north",
        "north",
        "east",
        "east",
        "take klein bottle",
        "north",
        "take hypercube",
        "north",
        ""
    ]))
    held = ITEMS.copy()
    choices = attempts()
    out_data = []
    thread = execute_program(instructions.copy(), partial(producer, in_data, held, choices), partial(consumer, out_data), False)
    thread.start()
    thread.join()
def main(instructions):
    data = {OUTP: [], PROG: [], PROC: []}
    data[PROG] = generate_program()
    execute_program(instructions.copy(), partial(producer, data),
                    partial(consumer, data), False).join()
    print(data[OUTP])
Esempio n. 7
0
    print(ch, end="")


def is_intersection(coord):
    global scaffolding
    return ((coord[0], coord[1] + 1) in scaffolding) \
           and ((coord[0], coord[1] - 1) in scaffolding) \
           and ((coord[0] + 1, coord[1]) in scaffolding) \
           and ((coord[0] - 1, coord[1]) in scaffolding)


fp = open("17.txt")
data = list(map(lambda x: int(x), fp.read().split(",")))

intcode.execute_program(data, None, output)

intersections = list(filter(is_intersection, scaffolding))
print(sum(map(lambda coord: coord[0] * coord[1], intersections)))


def right(d):
    if d == (1, 0):
        return 0, 1
    if d == (0, 1):
        return -1, 0
    if d == (-1, 0):
        return 0, -1
    if d == (0, -1):
        return 1, 0
Esempio n. 8
0
    63, 1005, 63, 619, 4, 599, 1001, 64, 1, 64, 1105, 1, 619, 1002, 64, 2, 64,
    109, 7, 1205, 1, 633, 4, 625, 1106, 0, 637, 1001, 64, 1, 64, 1002, 64, 2,
    64, 109, -8, 2102, 1, -3, 63, 1008, 63, 25, 63, 1005, 63, 659, 4, 643,
    1105, 1, 663, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, 14, 1206, -5, 679,
    1001, 64, 1, 64, 1105, 1, 681, 4, 669, 1002, 64, 2, 64, 109, -28, 2101, 0,
    2, 63, 1008, 63, 30, 63, 1005, 63, 707, 4, 687, 1001, 64, 1, 64, 1106, 0,
    707, 1002, 64, 2, 64, 109, 21, 21101, 46, 0, 0, 1008, 1019, 48, 63, 1005,
    63, 727, 1106, 0, 733, 4, 713, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, -3,
    21108, 47, 47, 1, 1005, 1017, 751, 4, 739, 1106, 0, 755, 1001, 64, 1, 64,
    1002, 64, 2, 64, 109, -13, 1207, 0, 37, 63, 1005, 63, 771, 1105, 1, 777, 4,
    761, 1001, 64, 1, 64, 1002, 64, 2, 64, 109, 7, 2108, 21, -9, 63, 1005, 63,
    797, 1001, 64, 1, 64, 1105, 1, 799, 4, 783, 1002, 64, 2, 64, 109, 22, 2106,
    0, -5, 1001, 64, 1, 64, 1106, 0, 817, 4, 805, 1002, 64, 2, 64, 109, -4,
    1205, -8, 829, 1106, 0, 835, 4, 823, 1001, 64, 1, 64, 1002, 64, 2, 64, 109,
    -4, 2105, 1, 0, 4, 841, 1105, 1, 853, 1001, 64, 1, 64, 1002, 64, 2, 64,
    109, -30, 1208, 6, 30, 63, 1005, 63, 871, 4, 859, 1105, 1, 875, 1001, 64,
    1, 64, 1002, 64, 2, 64, 109, -2, 1201, 9, 0, 63, 1008, 63, 22, 63, 1005,
    63, 897, 4, 881, 1106, 0, 901, 1001, 64, 1, 64, 4, 64, 99, 21101, 27, 0, 1,
    21102, 1, 915, 0, 1106, 0, 922, 21201, 1, 66266, 1, 204, 1, 99, 109, 3,
    1207, -2, 3, 63, 1005, 63, 964, 21201, -2, -1, 1, 21102, 942, 1, 0, 1105,
    1, 922, 22101, 0, 1, -1, 21201, -2, -3, 1, 21101, 0, 957, 0, 1106, 0, 922,
    22201, 1, -1, -2, 1105, 1, 968, 21202, -2, 1, -2, 109, -3, 2106, 0, 0
]


def get_input():
    return int(input('input: '))


intcode.execute_program(program, get_input, print)
def get_output_at(instructions, x, y):
    conf = dict(consume=[x, y])
    execute_program(instructions.copy(), partial(producer, conf), partial(consumer, conf), False).join()

    return conf["produce"]
Esempio n. 10
0
 def run(self):
     intcode.execute_program(self.program, self.get_input,
                             self.store_output)
     self.flood()
     sleep(100)
Esempio n. 11
0
 def run(self):
     intcode.execute_program(self.get_program(), self.get_input,
                             self.write_output)
Esempio n. 12
0
 def run(self, program):
     intcode.execute_program(program, self.get_current_panel_color,
                             self.output)
Esempio n. 13
0
import intcode

program = [
    1, 0, 0, 3, 1, 1, 2, 3, 1, 3, 4, 3, 1, 5, 0, 3, 2, 1, 10, 19, 1, 6, 19, 23,
    1, 10, 23, 27, 2, 27, 13, 31, 1, 31, 6, 35, 2, 6, 35, 39, 1, 39, 5, 43, 1,
    6, 43, 47, 2, 6, 47, 51, 1, 51, 5, 55, 2, 55, 9, 59, 1, 6, 59, 63, 1, 9,
    63, 67, 1, 67, 10, 71, 2, 9, 71, 75, 1, 6, 75, 79, 1, 5, 79, 83, 2, 83, 10,
    87, 1, 87, 5, 91, 1, 91, 9, 95, 1, 6, 95, 99, 2, 99, 10, 103, 1, 103, 5,
    107, 2, 107, 6, 111, 1, 111, 5, 115, 1, 9, 115, 119, 2, 119, 10, 123, 1, 6,
    123, 127, 2, 13, 127, 131, 1, 131, 6, 135, 1, 135, 10, 139, 1, 13, 139,
    143, 1, 143, 13, 147, 1, 5, 147, 151, 1, 151, 2, 155, 1, 155, 5, 0, 99, 2,
    0, 14, 0
]

memory = program.copy()
memory[1] = 12
memory[2] = 2

intcode.execute_program(memory, None, None)
print(memory[0])

for i in range(0, 99):
    for j in range(0, 99):
        memory = program.copy()
        memory[1] = i
        memory[2] = j
        intcode.execute_program(memory, None, None)
        if memory[0] == 19690720:
            print(100 * i + j)
            exit(1)