Esempio n. 1
0
from networkx import Graph, DiGraph, shortest_path, shortest_path_length, write_adjlist, read_adjlist, all_pairs_shortest_path_length

clean_prg = [int(x) for x in open("19/input.txt").read().strip().split(",")]

map = {}

inputs = []
coords = []
for x in range(50):
    for y in range(50):
        inputs += [x, y]
        coords.append((y, x))


def getc(coord):
    m = Machine(clean_prg.copy(), deque([coord[1], coord[0]]))
    for o in m.iter_output():
        return o


c = 0
for coord in coords:
    o = getc(coord)
    if o > 0:
        c += 1
    map[coord] = o

print(c)
ar = sparse_to_array(map)
draw(ar)
Esempio n. 2
0
        if i == 0:
            # hit a wall
            #print(f"hit wall at {trypos_t}")
            map[trypos_t] = 1
        elif i == 1:
            map[trypos_t] = 0
            g.add_edge(trypos_t, "untested")
            g.add_edge(curpos_t, trypos_t)
            g.add_edge(trypos_t, curpos_t)
            curpos = trypos[:]
        else:
            assert i == 2
            print("found home", trypos_t)
            print(shortest_path_length(g, (0, 0), curpos_t) + 1)
            write_adjlist(g, "15/found.adjlist")
            break


m = IterMachine(clean_prg, None)

it1, it2 = itertools.tee(m.iter_output())
m.inv = explore(it1)

tiles = {0: " ", 1: "#", 2: "x", 3: "-", 4: "o"}

for it, o in enumerate(it2):
    if it % 10000 == 0:
        draw(sparse_to_array(map), charmap=tiles)

draw(sparse_to_array(map), charmap=tiles)
Esempio n. 3
0
clean_prg = [int(x) for x in open("11/input.txt").read().strip().split(",")]

def drawer(ins):
    current_pos = (0,0)
    dir = (-1, 0)
    try:
        while 1:
            yield color.get(current_pos, 0)
            col = next(ins)
            dirchange = next(ins)
            color[current_pos] = col
            if dirchange == 0:
                dir = (-dir[1], dir[0])
            elif dirchange == 1:
                dir = (dir[1], -dir[0])
            else:
                print("bad dir")
            current_pos = tuple(np.array(current_pos) + np.array(dir))

    except StopIteration:
        print("program stopped")

inputq = collections.deque()
m = Machine(clean_prg, inputq)
color[(0, 0)] = 1
for current_color in drawer(m.iter_output()):
    inputq.append(current_color)

pic = sparse_to_array(color)
draw(pic)
Esempio n. 4
0
        lines = buf.split("\n")
        for i, line in enumerate(lines):
            if line.startswith("Items here:"):
                break
        for line in lines[i + 1:]:
            if line.startswith("- "):
                it = line[2:]
                if it not in forbidden:
                    # take
                    send("take " + it)
                    read(io)
            else:
                break

    map[cur] = 3
    draw(sparse_to_array(map))
    map[cur] = 0

    print(buf)

    mv = input().strip()
    if mv in shortcuts:
        mv = shortcuts[mv]

    if mv == "clear":
        cur = (0, 0)
        map = {cur: 0}
        continue

    if mv == "try":
        try_all_inv(io)
Esempio n. 5
0
from numpy import array as V
from lib.npdraw import draw, sparse_to_array
from lib.machine import Machine, IterMachine
from lib.parse import ReParse

clean_prg = [int(x) for x in open("13/input.txt").read().strip().split(",")]


def drawer(ins):
    while 1:
        try:
            x = next(ins)
            y = next(ins)
            t = next(ins)
            yield x, y, t
        except StopIteration:
            print("program stopped")
            return


m = Machine(clean_prg)
op = m.iter_output()

color = {}
for x, y, t in drawer(op):
    color[(x, y)] = t

tiles = {0: " ", 1: "#", 2: "x", 3: "-", 4: "o"}
draw(sparse_to_array(color), charmap=tiles)
print(sum(1 for c in color.values() if c == 2))
Esempio n. 6
0
    current_pos = (0,0)
    dir = (-1, 0)
    try:
        while 1:
            yield color.get(current_pos, 0)
            col = next(ins)
            dirchange = next(ins)
            color[current_pos] = col
            if dirchange == 0:
                dir = (-dir[1], dir[0])
            elif dirchange == 1:
                dir = (dir[1], -dir[0])
            else:
                print("bad dir")
            current_pos = tuple(np.array(current_pos) + np.array(dir))

    except StopIteration:
        print("program stopped")


q = deque()
m = Machine(clean_prg, q)
for col in drawer(m.iter_output()):
    q.append(col)

print(len(color))
from lib.npdraw import draw, sparse_to_array

draw(sparse_to_array(color))