\\ * * * * * * * * * * * * * * * \\ 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); \\ 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/krh init([ "......................", "....B...D....E...G....", "......................", "..A...C........F...H.." ]); link(pA, left(pH)); link(pA, pB); link(pA, pC); link(pA, down(pB)); link(pB, up(pC)); link(pB, pD); link(pB, pC); link(pC, pD); link(pC, down(pD)); link(pD, pE); link(pE, up(pF)); link(pE, pF); link(pE, pG); link(pF, pG); link(pF, down(pG)); link(pF, pH); link(pG, pH); link(pG, up(pH)); } allocatemem(2^30); \\ A301688 Coordination sequence for node of type V2 in "krh" 2-D tiling (or net). compute(pA, 1000); quit