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