コード例 #1
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
コード例 #2
0
ファイル: d11.py プロジェクト: otahontas/adventofcode
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))
コード例 #3
0
def solve(code):
    c = Comp(a);
    for i in code:
        for j in [ord(c) for c in i]:
            c.add_one_input(j)
        c.add_one_input(10)
    c.run()
    o = c.get_all_outputs()
    for output in o:
        if output <= 127:
            print(chr(output), end="")
        else:
            print("ans:", output)
コード例 #4
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