Skip to main content
2 of 3
added a commented version
Arnauld
  • 197.6k
  • 20
  • 179
  • 650

JavaScript (V8), 232 bytes

Prints the results as \$X_A,Y_A,X_B,Y_B\$.

n=>{for(o=[0,1,2,k=3];n;)for(z=++k**4;z--;)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]]|(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:o[print(A),A]=n--}

Try it online!

Commented

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
      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
      ( 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
      !n |                   //     or n = 0
      Y * x == X * y ?       //     or (0, 0), (x, y) and (X, Y) are co-linear:
        0                    //       do nothing
      :                      //     else:
        o[print(A), A] = n-- //       print A, set o[A] and decrement n
}                            //
Arnauld
  • 197.6k
  • 20
  • 179
  • 650