Example #1
0
def paint(start_from_white = False):
    x = n // 2 
    y = n // 2
    grid = [["."] * n for _ in range(n)]
    c = Comp(a)
    d = "U"
    colored = set()
    if start_from_white:
        grid[y][x] = "#"

    while not c.is_halted():
        inp = 0 if grid[y][x] == "." else 1
        c.add_one_input(inp)
        c.run()

        # Paint
        color = "." if c.get_one_output() == 0 else "#"
        grid[y][x] = color
        colored.add((y, x))

        # Turn
        if d == "U":
            d = "L" if c.get_one_output() == 0 else "R"
        elif d == "R":
            d = "U" if c.get_one_output() == 0 else "D"
        elif d == "D":
            d = "R" if c.get_one_output() == 0 else "L"
        elif d == "L":
            d = "D" if c.get_one_output() == 0 else "U"
        else:
            print("something not right)")
            break

        # Move
        if d == "U":
            y += 1
        elif d == "R":
            x += 1
        elif d == "D":
            y -= 1
        elif d == "L":
            x -= 1
        else:
            print("something not right)")
            break


    if start_from_white:
        A = np.asanyarray(grid)
        B= np.flipud(A)
        for row in B:
            print("".join(row))
    else:
        print(len(colored))
Example #2
0
def solve2():
    threshold = 100
    upleft_corners = {}
    y = 1200  # guessing that first suitable is after row 1200
    x_start = 0
    while True:
        hits = 0
        last_hit = 0
        x = x_start
        while True:
            c = Comp(a)
            c.add_one_input(x)
            c.add_one_input(y)
            c.run()
            o = c.get_one_output()
            if o == 1:
                if hits == 0:
                    x_start = x
                    possible_corner = y - threshold + 1
                    if (possible_corner in upleft_corners
                            and upleft_corners[possible_corner] == x):
                        return 10000 * x + possible_corner
                hits += 1
                last_hit = x
            if o == 0 and hits != 0:
                break
            x += 1
        if hits >= threshold:
            upleft_corners[y] = last_hit - threshold + 1
        y += 1
Example #3
0
def solve1():
    n = 50
    ans = 0
    for y in range(n):
        for x in range(n):
            c = Comp(a)
            c.add_one_input(x)
            c.add_one_input(y)
            c.run()
            o = c.get_one_output()
            if o == 1:
                ans += 1
    return ans
Example #4
0
def first():
    global grid
    global w
    global h
    c = Comp(a)
    c.run()

    sa = []
    while c.outputs:
        sa.append(chr(c.get_one_output()))

    s = "".join(sa)
    grid = s.splitlines()
    grid = grid[:-1]

    w = len(grid[0])
    h = len(grid)

    def is_intersection(y, x):
        if y < 1 or x < 1 or y > h - 2 or x > w - 2:
            return False
        if (grid[y][x] == "#" and grid[y - 1][x] == "#"
                and grid[y + 1][x] == "#" and grid[y][x - 1] == "#"
                and grid[y][x + 1] == "#"):
            return True
        return False

    ans = 0
    start = (0, 0)

    for y in range(h):
        for x in range(w):
            if grid[y][x] == "^":
                start = (y, x)
            if is_intersection(y, x):
                ans += y * x

    print(ans)
    return start