allocate mem(2^30) big = 1 000 000 s = 0 S = Set([]) unseen = 1 seen(v) = if (v < big, bit test(s, v), set search(S, v)) see(v) = if (v < big, s = bit or(s, 2^v), S = set union(S, Set([v]))); while (seen(unseen), unseen++) move(z) = { my (w=max(abs(real(z)), abs(imag(z)))); if (imag(z)==-w, z+1, real(z)==-w, z-I, imag(z)==+w, z-1, z+I); } M = 50 T = matrix(2*M+1, 2*M+1) out(z) = vecmax(apply(f -> abs(f(z)), [real, imag]))>M get(z) = if (out(z), 0, T[1+M+real(z), 1+M+imag(z)]) set(z, v) = T[1+M+real(z), 1+M+imag(z)] = v dz = powers(I, 3) divormul(v) = { fordiv (v, d, if (!seen(d), return (d); ); ); forstep (m=2*v, oo, v, if (!seen(m), return (m); ); ); } other(z) = { if (z==0, return (1), my (vv=Set(select(sign, apply(d -> get(d+z), dz)))); return (vecmin(apply(divormul, vv))); ); } { z=0; for (n=0, #T^2-1, v = other(z); see(v); set(z, v); print (n " " v); z = move(z); ); } quit