Example #1
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)))
Example #2
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))
Example #3
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)
Example #4
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)
Example #5
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)
Example #6
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])