big limit = 100 000 big values = Set([]) small values = vector(4, i, []) see index(z) = { my (s=1, x=real(z), y=imag(z)); if (x<1, s += 1; x = 1-x; ); if (y<0, s += 2; y = -y; ); return ([s,x,y]); } see(z) = { my (index = see index(z)); if (max(index[2],index[3]) > big limit, big values = set union(big values, Set([z])), if (#small values[index[1]] < index[2], small values[index[1]] = concat(small values[index[1]], vector(index[2] - #small values[index[1]])) ); small values[index[1]][index[2]] = bit or(small values[index[1]][index[2]], 2^index[3]) ); } seen(z) = { my (index = see index(z)); if (max(index[2],index[3]) > big limit, return (set search(big values, z)), if (#small values[index[1]] < index[2], return (0), return (bit test(small values[index[1]][index[2]], index[3])) ); ); } cell(z) = (real(z) - floor(imag(z)/2))%7 + I*(imag(z)%2); forbidden = [ [0, +1], \ [0, +I], \ [1, -1+I], \ [4+I, +I ], \ [4+I, 1], \ [5+I, -1+I] ]; forbidden = Set(concat(forbidden, apply(zd -> [cell(zd[1]+zd[2]), -zd[2]], forbidden))); accept(z, d) = !setsearch(forbidden, [cell(z), d]); dz = [ +1, -1, +I, -I, -1+I, +1-I ]; neighbours(z) = apply(d -> z+d, select(d -> accept(z,d), dz)); \\ coordinates for rendering flat(z) = 2*real(z) + (1+2*I) * imag(z); \\ -1 -> A320492 \\ -1+I -> A320493 \\ 0 -> A320494 current = Set(0) { for (r=0, 1 000, print (r " " #current); apply(see, current); current = Set(select(z -> !seen(z), Set(concat(apply(neighbours, current))))); ); } quit