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])) ); ); } dz = [2+I, 2-I] dz = concat(vector(4, k, dz*I^k)) neighbours(z) = vector(#dz, k, z+dz[k]); newcomers(z) = select(zz -> !seen(zz) && #select(seen, neighbours(zz))==1, neighbours(z)) allocate mem(2^30) gen = Set(0) nb = 0 { mx = 2^13; for (n=0, mx, print (n " " nb); nb += #gen; for (i=1, #gen, see(gen[i]); ); if (n!=mx, gen = Set(concat(apply(newcomers, gen))) ); ); } quit