\\ * * * * * * * * * * * * * * * \\ coordination sequence library \\ * * * * * * * * * * * * * * * width = -1 height = -1 coord = matrix(0,0) labels = matrix(0,0) init(screen) = { height = #screen; width = #screen[1]; coord = matrix(width, height, x, y, []); labels = matrix(width, height, x, y, ""); for (s=1, #screen, my (y=#screen - s); my (row = Vec(screen[s])); for (x=0, #row-1, my (d = row[x+1]); if ( (d >= "A" && d <= "Z") || (d >= "a" && d <= "Z") || (d >= "0" && d <= "9"), eval(Str("p" d "=" x+I*y)); labels[1+x, 1+y] = d; ); ); ); } up (z) = z + I*height down (z) = z - I*height right(z) = z + width left (z) = z - width \\ unidirectional link link1(z, zz) = { my (x=real(z) % width, y=imag(z) % height); coord[1+x, 1+y] = concat(coord[1+x, 1+y], zz-z); } \\ bidirectional link link(a, b) = link1(a, b); link1(b, a); \\ bidirectional links from same origin links(a, bb) = for (i=1, #bb, link(a, bb[i])); \\ neighbours neighbours(z) = { my (x=real(z) % width, y=imag(z) % height); my (n = apply (c -> c + z, coord[1+x, 1+y])); \\ print ("#" z " -> " n); return (n); } compute(z, mx) = { my (explored = Set()); my (current = Set(z)); for (n=0, mx, \\ print ("#" current); print (n " " #current); if (n==mx, break); explored = set union(explored, current); my (others = concat(apply(neighbours, current))); current = set minus(Set(others), explored); ); } { \\ http://rcsr.net/layers/kre init([ "....A.....B...", "C.............", ".......D......", "...E.......F..", ".......G......", "...H.......I..", ".......J......", "K.............", "....L.....M...", "N............." ]); links(pA, [ pC, pD, pB, up(pL), up(pN) ]); links(pB, [ up(pM), right(pC), pD, up(pM), up(right(pN)) ]); links(pC, [ up(pN), pE, left(pF) ]); links(pD, [ pE, pF, pG ]); links(pE, [ left(pF), pG, pH ]); links(pF, [ pG, pI ]); links(pG, [ pH, pI, pJ ]); links(pH, [ left(pI), pJ, pK ]); links(pI, [ pJ, right(pK) ]); links(pJ, [ pL, pM ]); links(pK, [ left(pM), pL, pN ]); links(pL, [ pM, pN ]); links(pM, [ right(pN) ]); links(pN, []); } \\ A301716 Coordination sequence for node of type V1 in "kre" 2-D tiling (or net). allocatemem(2^30) compute(pG, 1000) quit