n=>{for(o=[0,1,2,k=3];n;)for(z=++k**4;z--;)o[A=[xz=++k**4;o[A=[x,y,X,Y]=o.map(i=>~~(z/k**i)%k)]|o[[y,x,Y,X]]|o[[X,Y,x,y]]|o[[Y,X,y,x]]|x]]|Y*x==X*y|(g=d=>!d||[p,q=X*X+Y*Y,p+q-2*(x*X+y*Y)].some(v=>(v/d)**.5%1)*g(d-1))(p=x*x+y*y)|!n|Y*x==X*y?0--z:o[print(A),A]=nA]=--n;);}
Try it online!Try it online!
n => { // n = input
for( // outer loop:
o = [0, 1, 2, k = 3]; // o = [0, 1, 2, 3], re-used as an object to store
// the coordinates that were already tried
// k = counter
n; // loop until n = 0
) for(z = ++k ** 4; z--;) // inner loop: increment k and go from z = (k**4)-1 to// 0 inner loop:
z = o[++k ** 4; // increment k; start with z = //
k ** 4
o[ A = [x, y, X, Y] = // build the next tuple A = [x, y, X, Y]
o.map(i => // we try all tuples such that:
~~(z / k ** i) // 0 ≤ x < k, 0 ≤ y < k, 0 ≤ X < k, 0 ≤ Y < k
% k //
) //
] | // if [x, y, X, Y] was already tried
o[[y, x, Y, X]] | // or [y, x, Y, X] was already tried
o[[X, Y, x, y]] | // or [X, Y, x, y] was already tried
o[[Y, X, y, x]] | // or [Y, X, y, x] was already tried
Y * x == X * y | // or (0, 0), (x, y) and (X, Y) are co-linear
( g = d => // or g returns a truthy value:
!d || // stop if d = 0
[ // compute the squared distances:
p, // OA² = p = x² + y² (computed below)
q = X * X + Y * Y, // OB² = q = X² + Y²
p + q - 2 * // AB² = (X - x)² + (Y - y)² = p + q - 2(xX + yY)
(x * X + y * Y) //
].some(v => // test whether there's any v in the above list
(v / d) ** .5 % 1 // such that sqrt(v / d) is not an integer
) * g(d - 1) // and that this holds for d - 1
)(p = x * x + y * y) |? // initial call to g with d = p
p; if truthy:
!n | --z // or n =decrement 0z
: Y * x == X * y ? // or (0, 0),// (x, y) and (X, Y) are co-linearelse:
0 o[print(A), A] = --n; // do nothing
: print A, set o[A] and decrement n
); // else:
o[print(A), A] = n-- // print A, set o[A] and decrement n
} //