allocatemem(2^29) \\ .---.-.-. \\ | | | | \\ *---* | . \\ | | | | \\ .-*-*-*-*-. \\ | | | | \\ .---* | *---. \\ | | | | \\ .-O-*-*-*-. \\ | | | | \\ .---. | . neighbours(z) = { my (x=real(z)%4, y=imag(z)%4); if (x==0 && y==0, [ z+1, z-1, z+I, z-I ], x==1 && y==0, [ z+1, z-1, z+2*I ], x==2 && y==0, [ z+1, z-1, z+I, z-I ], x==3 && y==0, [ z+1, z-1, z-2*I ], x==0 && y==1, [ z-2, z+I, z-I ], x==2 && y==1, [ z+2, z+I, z-I ], x==0 && y==2, [ z+1, z-1, z+I, z-I ], x==1 && y==2, [ z+1, z-1, z-2*I ], x==2 && y==2, [ z+1, z-1, z+I, z-I ], x==3 && y==2, [ z+1, z-1, z+2*I ], x==0 && y==3, [ z+2, z+I, z-I ], x==2 && y==3, [ z-2, z+I, z-I ], print ("ouch"); quit ); } prev = Set() p = Set([1]) \\ points at distance = n { for (n=0, 1000, print (n " " #p); o = apply(neighbours, p); s = vecsum(apply(v->#v,o)); np = vector(s); k = 0; for (i=1, #o, for (j=1, #o[i], np[k++] = o[i][j]; )); prev = setunion(prev, p); p = setminus(Set(np), prev); ); } quit