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])) ); ); } \\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - neighbours = Set() { nmx = 100; my (stripes = vector(nmx+1, x1, x=x1-1; Set(vector(sqrt int(nmx^2 - x^2), y1, y=y1-1; z=x+y*I; [norm(z), z])))); while (#stripes > 1, stripes = vector(ceil(#stripes/2), s, if (2*s>#stripes, stripes[2*s-1], set union(stripes[2*s-1], stripes[2*s]))); ); neighbours = stripes[1]; } ppos = 0 pos = 0 nor = 0 a = vector(100) ok(n, z) = { for (i=1, n-2, for (j=i+1, n-1, if (imag( (a[i]-a[j]) / (a[i]-z) )==0, return (0); ); ); ); return (1) } other(n) = { my (old = pos - ppos); ppos = pos; if (n==1, pos = 0, n==2, pos = 1, my (best = 0, best n = 0, best i = 0); for (ne = 1, #neighbours, my (new = neighbours[ne]); if (best n && best n < new[1], break; ); for (rot=0, 3, my (ang = new[2] * I^rot / old); if (real(ang)>=0 && imag(ang)>0, if (!seen(pos + new[2] * I^rot), if (best n==0 || best i > imag(ang), best = new[2] * I^rot; best n = new[1]; best i = imag(ang); ); ); ); ); ); if (best, nor = best n; pos += best, print ("** oops"); quit ); ); see(pos); a[n] = pos; for (i=1, n-1, my (g=gcd(real(a[i]-a[n]), imag(a[i]-a[n]))); for (j=2, g-1, my (x = a[i] + (a[n]-a[i])*j/g ); see(x); ); ); } { for (n=1, #a, other(n); print (n " " real(pos)); ) } quit