Exemple #1
0
def main():
    p = Process(prog)
    x = 0
    y = 0
    pic = {}
    mx = 0
    for ot in p.run(until_halted=True).output:
        if ot == 10:
            y += 1

            x = 0
        else:
            pic[(x, y)] = chr(ot)
            x += 1
            mx = max(x, mx)

    my = y
    print(mx, my)
    for x in range(mx):
        print("".join(pic.get((x, y), " ") for y in range(my)))

    score = 0
    for x in range(mx):
        for y in range(my):
            p = (pic.get((x, y)), pic.get((x - 1, y)), pic.get(
                (x + 1, y)), pic.get((x, y - 1)), pic.get((x, y + 1)))
            if p == ("#", "#", "#", "#", "#"):
                score += x * y
    print(score)
Exemple #2
0
def main():

    print("Day *")
    p = Process(prog)

    def draw():
        screen = {}
        bits = chunks(p.output, 3)
        x_loc_O = 0
        x_loc__ = 0
        B_count = 0
        for x, y, t in bits:
            screen[(x, y)] = t
            if t == 2:
                B_count += 1
            if t == 3:
                x_loc__ = x
            if t == 4:
                x_loc_O = x
        if B_count == 0:
            print_screen(screen)
            time.sleep(1)
        if x_loc_O < x_loc__:
            return -1
        if x_loc_O > x_loc__:
            return 1

        return 0

    p.run(until_halted=True, in_fn=draw)
    bits = chunks(p.output, 3)
    screen = {}
    for x, y, t in bits:
        screen[(x, y)] = t
    print(screen.get((-1, 0)))
Exemple #3
0
def main():
    count = 0
    for y in range(20):
        s = ""
        for x in range(20):
            p = Process(prog)
            l = p.run(inpt=[x, y]).output[-1]
            count += l
            s += str(l)
        print(s)
    print(count)
Exemple #4
0
 def __init__(self, area):
     self.location = (0, 0)
     self.area = area
     self.cpu = CPU()
     self.process = Process(Memory(read_program('input.txt')))
     self.process.io.wait_input = self.provide_input
     self.process.io.listeners = [self.handle_output]
     self.latest_direction = Direction.UP
     self.location_gen = next_location_generator(self.location, self.area)
Exemple #5
0
def main():
    for part in (0,1):
        print(f"Day 11 part {part+1}")
        panels = defaultdict(lambda :0)
        panels[(0,0)]=part
        painted =set()
        c = Process([3,8,1005,8,318,1106,0,11,0,0,0,104,1,104,0,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,102,1,8,29,1006,0,99,1006,0,81,1006,0,29,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,1001,8,0,59,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,1,10,4,10,102,1,8,82,1,1103,3,10,2,104,14,10,3,8,102,-1,8,10,101,1,10,10,4,10,108,1,8,10,4,10,102,1,8,111,1,108,2,10,2,1101,7,10,1,1,8,10,1,1009,5,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,102,1,8,149,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,1,10,4,10,101,0,8,172,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,0,8,10,4,10,1001,8,0,193,1006,0,39,2,103,4,10,2,1103,20,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,0,10,4,10,102,1,8,227,1,1106,8,10,2,109,15,10,2,106,14,10,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,1,10,4,10,101,0,8,261,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,0,10,4,10,102,1,8,283,1,1109,9,10,2,1109,5,10,2,1,2,10,1006,0,79,101,1,9,9,1007,9,1087,10,1005,10,15,99,109,640,104,0,104,1,21101,936333124392,0,1,21101,0,335,0,1106,0,439,21102,1,824663880596,1,21102,346,1,0,1105,1,439,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21102,1,179519553539,1,21101,393,0,0,1106,0,439,21102,46266515623,1,1,21101,0,404,0,1106,0,439,3,10,104,0,104,0,3,10,104,0,104,0,21101,0,983925826324,1,21101,0,427,0,1106,0,439,21101,988220642048,0,1,21102,1,438,0,1105,1,439,99,109,2,21201,-1,0,1,21102,1,40,2,21101,0,470,3,21101,460,0,0,1106,0,503,109,-2,2105,1,0,0,1,0,0,1,109,2,3,10,204,-1,1001,465,466,481,4,0,1001,465,1,465,108,4,465,10,1006,10,497,1101,0,0,465,109,-2,2106,0,0,0,109,4,2102,1,-1,502,1207,-3,0,10,1006,10,520,21101,0,0,-3,22102,1,-3,1,21202,-2,1,2,21102,1,1,3,21102,1,539,0,1105,1,544,109,-4,2106,0,0,109,5,1207,-3,1,10,1006,10,567,2207,-4,-2,10,1006,10,567,21202,-4,1,-4,1106,0,635,21202,-4,1,1,21201,-3,-1,2,21202,-2,2,3,21102,1,586,0,1105,1,544,21202,1,1,-4,21102,1,1,-1,2207,-4,-2,10,1006,10,605,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,627,21202,-1,1,1,21102,1,627,0,105,1,502,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2106,0,0])
        pos = (0,0)
        di = UP
        while not c.state.halted:
        
            current_colour = panels[pos]
            c.run([current_colour])
            new_colour = c.output[-1]
            c.run()
            panels[pos] = new_colour
            painted.add(pos)
            new_dir = c.output[-1]

        
            if new_dir == 0:
                  di = (di[1], -di[0])
            if new_dir ==1:
                  di = (-di[1], di[0])
            pos = (pos[0]+di[0], pos[1]+di[1])
   
        print_panels(panels)
        print(len(painted))
Exemple #6
0
    1, 64, 1105, 1, 545, 1002, 64, 2, 64, 109, 3, 1201, 0, 0, 63, 1008, 63, 36,
    63, 1005, 63, 571, 4, 551, 1001, 64, 1, 64, 1105, 1, 571, 1002, 64, 2, 64,
    109, 1, 21107, 44, 45, 7, 1005, 1014, 593, 4, 577, 1001, 64, 1, 64, 1106,
    0, 593, 1002, 64, 2, 64, 109, 7, 1205, 6, 609, 1001, 64, 1, 64, 1106, 0,
    611, 4, 599, 1002, 64, 2, 64, 109, -14, 1202, 4, 1, 63, 1008, 63, 32, 63,
    1005, 63, 635, 1001, 64, 1, 64, 1106, 0, 637, 4, 617, 1002, 64, 2, 64, 109,
    30, 1205, -9, 651, 4, 643, 1105, 1, 655, 1001, 64, 1, 64, 1002, 64, 2, 64,
    109, -4, 2106, 0, 2, 4, 661, 1106, 0, 673, 1001, 64, 1, 64, 1002, 64, 2,
    64, 109, -5, 21101, 45, 0, -8, 1008, 1013, 42, 63, 1005, 63, 697, 1001, 64,
    1, 64, 1106, 0, 699, 4, 679, 1002, 64, 2, 64, 109, -10, 1207, -6, 27, 63,
    1005, 63, 721, 4, 705, 1001, 64, 1, 64, 1105, 1, 721, 1002, 64, 2, 64, 109,
    -11, 2101, 0, 6, 63, 1008, 63, 36, 63, 1005, 63, 743, 4, 727, 1106, 0, 747,
    1001, 64, 1, 64, 1002, 64, 2, 64, 109, 3, 2102, 1, -2, 63, 1008, 63, 33,
    63, 1005, 63, 767, 1105, 1, 773, 4, 753, 1001, 64, 1, 64, 1002, 64, 2, 64,
    109, 18, 1206, 0, 789, 1001, 64, 1, 64, 1106, 0, 791, 4, 779, 1002, 64, 2,
    64, 109, -11, 1208, -5, 23, 63, 1005, 63, 807, 1106, 0, 813, 4, 797, 1001,
    64, 1, 64, 1002, 64, 2, 64, 109, -5, 21102, 46, 1, 10, 1008, 1015, 46, 63,
    1005, 63, 835, 4, 819, 1105, 1, 839, 1001, 64, 1, 64, 1002, 64, 2, 64, 109,
    11, 2105, 1, 7, 1106, 0, 857, 4, 845, 1001, 64, 1, 64, 1002, 64, 2, 64,
    109, 14, 2106, 0, -3, 1001, 64, 1, 64, 1106, 0, 875, 4, 863, 1002, 64, 2,
    64, 109, -22, 21102, 47, 1, 5, 1008, 1013, 48, 63, 1005, 63, 899, 1001, 64,
    1, 64, 1106, 0, 901, 4, 881, 4, 64, 99, 21102, 1, 27, 1, 21102, 915, 1, 0,
    1105, 1, 922, 21201, 1, 65718, 1, 204, 1, 99, 109, 3, 1207, -2, 3, 63,
    1005, 63, 964, 21201, -2, -1, 1, 21102, 1, 942, 0, 1105, 1, 922, 22101, 0,
    1, -1, 21201, -2, -3, 1, 21102, 957, 1, 0, 1106, 0, 922, 22201, 1, -1, -2,
    1105, 1, 968, 21201, -2, 0, -2, 109, -3, 2105, 1, 0
]

print(Process(BOOST_PROD).run(inpt=[1], until_halted=True).output)
print(Process(BOOST_PROD).run(inpt=[2], until_halted=True).output)
Exemple #7
0
    if grid[y][x] != 35:
        return False
    total_neighbours = 0
    for dx, dy in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        try:
            if grid[y + dy][x + dx] == 35:
                total_neighbours += 1
        except IndexError:
            pass
    return total_neighbours >= 3


if __name__ == '__main__':
    scaffolding = []
    cpu = CPU()
    process = Process(Memory(read_program('input.txt')))
    collector = OutputCollector(
        output_method=OutputCollector.Method.END_INT_EXCLUDE,
        output_until=10,
        callback=lambda val: scaffolding.append(val))
    collector.attach(process)
    cpu.process(process)
    print('\n'.join(''.join(chr(x) for x in sub) for sub in scaffolding))

    total_alignment_parameter = 0
    for y, row in enumerate(scaffolding):
        for x, el in enumerate(row):
            if is_intersection(x, y, scaffolding):
                total_alignment_parameter += x * y
    write_output(total_alignment_parameter)
    print(f'Total alignment: {total_alignment_parameter}')
Exemple #8
0
def main():
    print("Day *")
    pos = (0, 0)
    di = 3
    screen = {}
    screen[pos] = '.'
    count = {}
    count[pos] = 0
    p = Process(prog)
    c = 0
    while True:
        c += 1
        while True:
            if screen.get(get_n(pos, left(di))) != "#":
                di = left(di)
                break
            if screen.get(get_n(pos, (di))) != "#":

                break
            di = right(di)
            break
        l = p.run([di]).output[-1]

        n = get_n(pos, di)
        if l == 0:
            screen[n] = "#"
        if (n not in count):
            count[n] = count[pos] + 1
        if l == 1:
            screen[n] = "."
            pos = n
        if l == 2:
            screen[n] = "O"

            ps(screen, pos)
            print("here", count[n])
            print(n)

            break

        if c % 1000 == 0:
            time.sleep(1)
            ps(screen, pos)

    one_changed = True
    c = -1
    while one_changed:
        one_changed = False
        c += 1
        to_change = []
        for point in screen:
            if screen[point] == ".":
                around = [get_n(point, i + 1) for i in range(4)]
                if any(screen.get(p) == "O" for p in around):

                    to_change.append(point)
                    one_changed = True
        for point in to_change:
            screen[point] = "O"
        ps(screen, pos)
        #time.sleep(1)
    print(c)
Exemple #9
0
# Itertools Functions:
# product('ABCD', repeat=2)                   AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD
# permutations('ABCD', 2)                     AB AC AD BA BC BD CA CB CD DA DB DC
# combinations('ABCD', 2)                     AB AC AD BC BD CD
# combinations_with_replacement('ABCD', 2)    AA AB AC AD BB BC BD CC CD DD

from computer import Process

prog = [3,62,1001,62,11,10,109,2257,105,1,0,1119,1088,1678,1851,2222,1647,606,1707,785,1445,1220,1886,1160,818,1546,882,1820,1950,2055,1779,1408,1919,1987,571,1476,985,709,2088,680,1515,2191,647,1348,2158,950,1191,742,1744,1317,1610,1286,2018,851,1016,919,1249,1377,2117,1579,1051,0,0,0,0,0,0,0,0,0,0,0,0,3,64,1008,64,-1,62,1006,62,88,1006,61,170,1106,0,73,3,65,21001,64,0,1,20102,1,66,2,21102,1,105,0,1106,0,436,1201,1,-1,64,1007,64,0,62,1005,62,73,7,64,67,62,1006,62,73,1002,64,2,133,1,133,68,133,102,1,0,62,1001,133,1,140,8,0,65,63,2,63,62,62,1005,62,73,1002,64,2,161,1,161,68,161,1101,1,0,0,1001,161,1,169,1002,65,1,0,1101,0,1,61,1101,0,0,63,7,63,67,62,1006,62,203,1002,63,2,194,1,68,194,194,1006,0,73,1001,63,1,63,1106,0,178,21102,210,1,0,105,1,69,1202,1,1,70,1101,0,0,63,7,63,71,62,1006,62,250,1002,63,2,234,1,72,234,234,4,0,101,1,234,240,4,0,4,70,1001,63,1,63,1106,0,218,1106,0,73,109,4,21102,1,0,-3,21102,0,1,-2,20207,-2,67,-1,1206,-1,293,1202,-2,2,283,101,1,283,283,1,68,283,283,22001,0,-3,-3,21201,-2,1,-2,1106,0,263,22101,0,-3,-3,109,-4,2105,1,0,109,4,21102,1,1,-3,21101,0,0,-2,20207,-2,67,-1,1206,-1,342,1202,-2,2,332,101,1,332,332,1,68,332,332,22002,0,-3,-3,21201,-2,1,-2,1106,0,312,22101,0,-3,-3,109,-4,2106,0,0,109,1,101,1,68,358,21001,0,0,1,101,3,68,366,21002,0,1,2,21102,1,376,0,1105,1,436,22102,1,1,0,109,-1,2105,1,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21202,-6,10,-5,22207,-7,-5,-5,1205,-5,521,21102,0,1,-4,21102,0,1,-3,21102,1,51,-2,21201,-2,-1,-2,1201,-2,385,471,20102,1,0,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,496,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,515,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,461,1106,0,547,21101,0,-1,-4,21202,-6,-1,-6,21207,-7,0,-5,1205,-5,547,22201,-7,-6,-7,21201,-4,1,-4,1106,0,529,21202,-4,1,-7,109,-8,2106,0,0,109,1,101,1,68,563,21002,0,1,0,109,-1,2106,0,0,1101,50263,0,66,1101,0,3,67,1102,1,598,68,1102,302,1,69,1102,1,1,71,1102,604,1,72,1106,0,73,0,0,0,0,0,0,6,195758,1102,1,97879,66,1102,1,6,67,1102,633,1,68,1102,253,1,69,1102,1,1,71,1102,645,1,72,1105,1,73,0,0,0,0,0,0,0,0,0,0,0,0,11,35974,1101,34897,0,66,1102,1,1,67,1101,0,674,68,1101,556,0,69,1102,1,2,71,1101,676,0,72,1105,1,73,1,11,24,161373,20,297753,1102,1,55763,66,1102,1,1,67,1101,0,707,68,1101,556,0,69,1101,0,0,71,1101,0,709,72,1106,0,73,1,1753,1101,6389,0,66,1101,0,2,67,1101,0,736,68,1102,1,351,69,1102,1,1,71,1102,740,1,72,1106,0,73,0,0,0,0,255,15461,1102,1,353,66,1102,1,1,67,1101,769,0,68,1102,556,1,69,1102,7,1,71,1101,771,0,72,1105,1,73,1,1,49,48779,23,50263,45,209548,37,172358,24,107582,7,186562,4,47798,1102,1,68171,66,1102,1,2,67,1102,1,812,68,1102,1,302,69,1101,0,1,71,1101,0,816,72,1106,0,73,0,0,0,0,39,299361,1101,82963,0,66,1101,0,1,67,1102,1,845,68,1102,556,1,69,1102,2,1,71,1101,0,847,72,1105,1,73,1,10,15,100379,47,12377,1102,1,24391,66,1102,1,1,67,1102,1,878,68,1102,556,1,69,1101,0,1,71,1101,880,0,72,1105,1,73,1,21,24,53791,1101,100379,0,66,1102,4,1,67,1101,0,909,68,1101,0,302,69,1102,1,1,71,1101,917,0,72,1105,1,73,0,0,0,0,0,0,0,0,47,61885,1102,92363,1,66,1101,0,1,67,1102,946,1,68,1101,556,0,69,1102,1,1,71,1101,0,948,72,1106,0,73,1,160,47,37131,1102,1,90089,66,1101,3,0,67,1101,0,977,68,1102,302,1,69,1101,0,1,71,1102,1,983,72,1105,1,73,0,0,0,0,0,0,39,399148,1102,57557,1,66,1102,1,1,67,1101,1012,0,68,1101,0,556,69,1102,1,1,71,1101,1014,0,72,1106,0,73,1,733,37,86179,1102,72977,1,66,1101,0,1,67,1101,1043,0,68,1102,556,1,69,1101,0,3,71,1101,0,1045,72,1106,0,73,1,5,15,301137,15,401516,47,49508,1101,0,48779,66,1102,4,1,67,1101,0,1078,68,1102,302,1,69,1102,1,1,71,1101,0,1086,72,1106,0,73,0,0,0,0,0,0,0,0,6,587274,1102,99881,1,66,1102,1,1,67,1101,0,1115,68,1101,0,556,69,1102,1,1,71,1102,1,1117,72,1105,1,73,1,-95,37,258537,1102,15461,1,66,1101,0,1,67,1102,1146,1,68,1102,1,556,69,1102,1,6,71,1101,1148,0,72,1105,1,73,1,23892,8,136342,3,182738,3,274107,34,90089,34,180178,34,270267,1102,93253,1,66,1102,1,1,67,1101,0,1187,68,1101,556,0,69,1102,1,1,71,1102,1189,1,72,1105,1,73,1,569,23,100526,1102,1,37997,66,1102,1,1,67,1102,1218,1,68,1101,556,0,69,1102,1,0,71,1102,1220,1,72,1106,0,73,1,1682,1101,0,68399,66,1102,1,1,67,1102,1247,1,68,1102,556,1,69,1102,1,0,71,1101,0,1249,72,1105,1,73,1,1850,1102,52387,1,66,1101,4,0,67,1102,1,1276,68,1102,1,302,69,1102,1,1,71,1102,1,1284,72,1106,0,73,0,0,0,0,0,0,0,0,6,489395,1102,60659,1,66,1102,1,1,67,1102,1,1313,68,1102,1,556,69,1101,1,0,71,1102,1315,1,72,1105,1,73,1,293,7,93281,1101,0,85853,66,1102,1,1,67,1101,0,1344,68,1101,556,0,69,1102,1,1,71,1102,1,1346,72,1105,1,73,1,-183,17,378236,1102,1,97987,66,1102,1,1,67,1101,0,1375,68,1101,556,0,69,1101,0,0,71,1101,1377,0,72,1105,1,73,1,1347,1101,26371,0,66,1101,0,1,67,1101,0,1404,68,1101,0,556,69,1102,1,1,71,1102,1406,1,72,1105,1,73,1,-27,4,71697,1101,0,99251,66,1101,4,0,67,1101,0,1435,68,1102,302,1,69,1101,1,0,71,1101,0,1443,72,1106,0,73,0,0,0,0,0,0,0,0,39,199574,1101,40973,0,66,1102,1,1,67,1102,1,1472,68,1101,0,556,69,1101,1,0,71,1102,1474,1,72,1106,0,73,1,125,15,200758,1102,1,53791,66,1102,5,1,67,1101,0,1503,68,1102,302,1,69,1102,1,1,71,1101,0,1513,72,1105,1,73,0,0,0,0,0,0,0,0,0,0,6,391516,1101,0,31277,66,1102,1,1,67,1101,0,1542,68,1101,556,0,69,1102,1,1,71,1101,0,1544,72,1106,0,73,1,128,23,150789,1101,77291,0,66,1101,1,0,67,1102,1573,1,68,1102,556,1,69,1101,0,2,71,1101,0,1575,72,1106,0,73,1,191,49,97558,49,195116,1102,1,91753,66,1102,1,1,67,1101,0,1606,68,1102,1,556,69,1102,1,1,71,1102,1,1608,72,1106,0,73,1,61,17,94559,1102,99787,1,66,1102,4,1,67,1102,1637,1,68,1101,0,253,69,1102,1,1,71,1101,0,1645,72,1105,1,73,0,0,0,0,0,0,0,0,26,6389,1102,8081,1,66,1101,1,0,67,1101,0,1674,68,1102,556,1,69,1102,1,1,71,1101,1676,0,72,1105,1,73,1,8929,7,279843,1101,0,43997,66,1102,1,1,67,1102,1705,1,68,1101,0,556,69,1102,0,1,71,1101,0,1707,72,1106,0,73,1,1165,1102,1,93281,66,1102,4,1,67,1102,1,1734,68,1101,0,302,69,1102,1,1,71,1102,1,1742,72,1105,1,73,0,0,0,0,0,0,0,0,8,68171,1102,1,86179,66,1101,3,0,67,1102,1771,1,68,1101,302,0,69,1101,0,1,71,1102,1,1777,72,1105,1,73,0,0,0,0,0,0,6,97879,1101,14057,0,66,1102,1,1,67,1101,0,1806,68,1102,1,556,69,1101,0,6,71,1102,1808,1,72,1106,0,73,1,3,49,146337,45,52387,24,215164,11,17987,18,53974,20,99251,1102,1,69389,66,1102,1,1,67,1101,0,1847,68,1102,556,1,69,1102,1,1,71,1101,0,1849,72,1106,0,73,1,109,45,104774,1102,91369,1,66,1101,0,3,67,1102,1878,1,68,1101,302,0,69,1102,1,1,71,1101,1884,0,72,1105,1,73,0,0,0,0,0,0,39,99787,1101,0,17987,66,1101,0,2,67,1101,1913,0,68,1101,302,0,69,1102,1,1,71,1101,0,1917,72,1106,0,73,0,0,0,0,18,26987,1102,90173,1,66,1102,1,1,67,1102,1,1946,68,1101,0,556,69,1102,1,1,71,1101,0,1948,72,1106,0,73,1,-281,45,157161,1101,0,94559,66,1101,0,4,67,1101,0,1977,68,1101,0,302,69,1101,1,0,71,1101,1985,0,72,1106,0,73,0,0,0,0,0,0,0,0,6,293637,1102,13477,1,66,1101,0,1,67,1102,2014,1,68,1101,556,0,69,1101,1,0,71,1102,2016,1,72,1106,0,73,1,514,24,268955,1101,0,97871,66,1101,0,1,67,1102,2045,1,68,1102,556,1,69,1101,0,4,71,1102,2047,1,72,1106,0,73,1,2,17,189118,17,283677,47,24754,47,74262,1102,26987,1,66,1101,0,2,67,1102,2082,1,68,1102,1,302,69,1102,1,1,71,1101,2086,0,72,1106,0,73,0,0,0,0,20,198502,1101,92987,0,66,1101,0,1,67,1102,1,2115,68,1102,1,556,69,1102,0,1,71,1102,2117,1,72,1106,0,73,1,1857,1101,12377,0,66,1102,6,1,67,1101,0,2144,68,1101,302,0,69,1102,1,1,71,1101,2156,0,72,1106,0,73,0,0,0,0,0,0,0,0,0,0,0,0,26,12778,1102,69371,1,66,1102,1,1,67,1102,2185,1,68,1101,556,0,69,1102,2,1,71,1102,1,2187,72,1106,0,73,1,1889,20,397004,4,23899,1102,1,52861,66,1102,1,1,67,1101,0,2218,68,1101,556,0,69,1102,1,1,71,1102,2220,1,72,1105,1,73,1,599,7,373124,1101,23899,0,66,1102,1,3,67,1102,1,2249,68,1101,0,302,69,1102,1,1,71,1102,2255,1,72,1106,0,73,0,0,0,0,0,0,3,91369]


network = {}
for i in range(50):
    
    network[i] = Process(prog,name=str(i)).run(inpt=[i], in_fn = (lambda : -1), until_input_needed=True)

nat = (0,0)
nats = set()
while True:
    all_idle = True
    for i in range(50):
        c = network[i]

            
        if len(c.output) == 3:
            
            addr = c.output.pop(0)
            assert (0<=addr<50) or addr==255
            x = c.output.pop(0)
            y = c.output.pop(0)
Exemple #10
0
def is_in(point):
    return Process(prog).run(inpt=list(point)).output[-1] == 1
Exemple #11
0
 def __init__(self, raw_memory):
     self.position = (0, 0)
     self.direction = Direction.UP
     self.process = Process(Memory(raw_memory))
     self.values = []
Exemple #12
0
def main():
    p = Process(prog)
    x = 0
    y = 0
    pic = {}
    mx = 0
    rob = None
    for ot in p.run(until_halted=True).output:
        if ot == 10:
            y += 1

            x = 0
        else:
            c = chr(ot)
            if c == "^":
                rob = (x, y)
            pic[(x, y)] = c
            x += 1
            mx = max(x, mx)

    my = y
    print(mx, my)
    for y in range(my):
        print("".join(pic.get((x, y), " ") for x in range(mx)))

    score = 0
    for x in range(mx):
        for y in range(my):
            p = (pic.get((x, y)), pic.get((x - 1, y)), pic.get(
                (x + 1, y)), pic.get((x, y - 1)), pic.get((x, y + 1)))
            if p == ("#", "#", "#", "#", "#"):
                score += x * y
    print(score)

    ##................##########^........
    ##................#..................
    ##................#..................
    ##................#..................
    ##................#..................
    ##................#..................
    ##................#..................
    ##................#..................
    ##................#..................
    ##................#..................
    ##..........#######..................
    ##..........#........................
    ##..........#........................
    ##..........#........................
    ##..........#........................
    ##..........#........................
    ##..........#........................
    ##..........#........................
    ##..........#........................
    ##..........#........................
    ##..........###########..............
    ##....................#..............
    ##....................#..............
    ##....................#..............
    ##..............#############........
    ##..............#.....#.....#........
    ##........#############.....#........
    ##........#.....#...........#........
    ##........#.....#...........#........
    ##........#.....#...........#........
    ###############.###########.#........
    ###.......#...#...........#.#........
    ###.....#############.....#.#........
    ###.....#.#...#.....#.....#.#........
    ###.....#.#...#.....#.....#.#.#######
    ###.....#.#...#.....#.....#.#.#......
    ###.....#.#...#.#############.#......
    ###.....#.#...#.#...#.....#...#......
    ###.....#.#############...#.#######..
    ###.....#.....#.#...#.#...#.#.#...#..
    ###.....#.....#.#...#.#...#.#.#...#..
    ###.....#.....#.#...#.#...#.#.#...#..
    #########.....#############.#.#...#..
    ##..............#...#.#.....#.#...#..
    ##..............#...###########...#..
    ##..............#.....#.....#.....#..
    ##..............#.....#.....#.....#..
    ##..............#.....#.....#.....#..
    ##..............#############.....#..
    ##....................#...........#..
    ##....................#############..

    dirs = [(0, -1), (1, 0), (0, 1), (-1, 0)]
    di = -1

    out = ["L"]

    c = 0
    while True:

        if (pic.get(add(rob, dirs[di])) != "#") and (pic.get(
                add(rob, dirs[(di + 1) % 4])) != "#") and (pic.get(
                    add(rob, dirs[(di - 1) % 4])) != "#"):
            out.append(c)
            break

        if pic.get(add(rob, dirs[di])) == "#":
            c += 1
            rob = add(rob, dirs[di])
        else:
            out.append(c)
            c = 0
            if pic.get(add(rob, dirs[(di + 1) % 4])) == "#":
                out.append("R")
                di = (di + 1) % 4
            elif pic.get(add(rob, dirs[(di - 1) % 4])) == "#":
                out.append("L")
                di = (di - 1) % 4
            else:
                raise Exception("BOOM")

    print(",".join(str(o) for o in out))

    ans = """A,A,B,B,C,B,C,B,C,A
L,10,L,10,R,6
R,12,L,12,L,12
L,6,L,10,R,12,R,12
n
"""

    ans = [ord(a) for a in ans]
    print(ans)
    prog[0] = 2
    p = Process(prog)
    p.run(ans, until_halted=True)
    print(p.output[-1])
Exemple #13
0
    -5, 1, -9, 1205, -9, 1837, 21208, -5, 2, -9, 1205, -9, 1844, 21208, -3, 0,
    -1, 1105, 1, 1855, 22202, -3, -1, -1, 1105, 1, 1855, 22201, -3, -1, -1,
    22107, 0, -1, -1, 1106, 0, 1855, 21208, -2, -1, -9, 1206, -9, 1869, 21201,
    -1, 0, -8, 1106, 0, 1873, 21202, -1, 1, -7, 21201, -6, 1, -6, 1106, 0,
    1708, 21202, -8, 1, -10, 109, -11, 2106, 0, 0, 109, 7, 22207, -6, -5, -3,
    22207, -4, -6, -2, 22201, -3, -2, -1, 21208, -1, 0, -6, 109, -7, 2106, 0,
    0, 0, 109, 5, 1201, -2, 0, 1912, 21207, -4, 0, -1, 1206, -1, 1930, 21101,
    0, 0, -4, 21201, -4, 0, 1, 21201, -3, 0, 2, 21101, 0, 1, 3, 21102, 1949, 1,
    0, 1105, 1, 1954, 109, -5, 2105, 1, 0, 109, 6, 21207, -4, 1, -1, 1206, -1,
    1977, 22207, -5, -3, -1, 1206, -1, 1977, 21201, -5, 0, -5, 1106, 0, 2045,
    21202, -5, 1, 1, 21201, -4, -1, 2, 21202, -3, 2, 3, 21102, 1996, 1, 0,
    1106, 0, 1954, 22102, 1, 1, -5, 21101, 1, 0, -2, 22207, -5, -3, -1, 1206,
    -1, 2015, 21102, 0, 1, -2, 22202, -3, -2, -3, 22107, 0, -4, -1, 1206, -1,
    2037, 22102, 1, -2, 1, 21102, 1, 2037, 0, 105, 1, 1912, 21202, -3, -1, -3,
    22201, -5, -3, -5, 109, -6, 2105, 1, 0
]

springcode = """NOT A J  
NOT C T  
AND D T  
OR T J
WALK
"""

sc = [ord(a) for a in springcode]
print(sc)

a = Process(prog).run(sc, until_halted=True).output
print(a)
print("".join(chr(b) for b in a))
Exemple #14
0
            if ball[1] < closest[1]:
                closest = ball
        paddle_middle_x = self.paddle[int(len(self.paddle) / 2)]
        if closest[0] == paddle_middle_x:
            return 0
        elif closest[0] > paddle_middle_x:
            return 1
        return -1


def write_output(result):
    with open('output.txt', 'w') as out_file:
        out_file.write(str(result))
        out_file.write('\n')


if __name__ == '__main__':
    game = Game()
    cpu = CPU()
    memory = Memory(read_program('input.txt'))
    # coins are at mem address 0
    # 2 coins means free play
    memory.memory[0] = 2
    process = Process(memory)
    collector = OutputCollector(3, game.handle_program_output)
    collector.attach(process)
    process.io.wait_input = game.handle_program_input
    cpu.process(process)
    write_output(game.score)
    print(f'Game has finished with score {game.score}')