Skip to main content
added 38 characters in body
Source Link
ophact
  • 3.2k
  • 1
  • 7
  • 24

JavaScript (Node.js), 336334 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5c*c==n?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...f(R*R).flatMap(e=>f(T*T).flatMap(E=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

Thanks to @Neil for saving 2 bytes.

JavaScript (Node.js), 336 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...f(R*R).flatMap(e=>f(T*T).flatMap(E=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

JavaScript (Node.js), 334 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c*c==n?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...f(R*R).flatMap(e=>f(T*T).flatMap(E=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

Thanks to @Neil for saving 2 bytes.

deleted 12 characters in body
Source Link
ophact
  • 3.2k
  • 1
  • 7
  • 24

JavaScript (Node.js), 336 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...f(R*R).flatMap(e=>f(T*T).flatMap(E=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

UPDATE: The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

JavaScript (Node.js), 336 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...f(R*R).flatMap(e=>f(T*T).flatMap(E=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

UPDATE: The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

JavaScript (Node.js), 336 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...f(R*R).flatMap(e=>f(T*T).flatMap(E=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

deleted 26 characters in body
Source Link
ophact
  • 3.2k
  • 1
  • 7
  • 24

JavaScript (Node.js), 348336 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),A=f(R*R),B=f(T*T),C=f(U*U),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...Af(R*R).flatMap(e=>Be=>f(T*T).flatMap(E=>CE=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

UPDATE: The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

JavaScript (Node.js), 348 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),A=f(R*R),B=f(T*T),C=f(U*U),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...A.flatMap(e=>B.flatMap(E=>C.map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

UPDATE: The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

JavaScript (Node.js), 336 bytes

([P,Q,R,S,T,U],f=(n,j=0,c=n**.5|0)=>j>1?c==n**.5?[[-c],[c]]:[['']]:[...Array(1+2*c)].flatMap((_,i)=>i?f(n-(i-c)**2,j+1).map(b=>[i-c,...b]).filter(e=>!e.includes('')):[]),t=(y,z)=>y.map((e,i)=>Z+=(e-z[i])**2,Z=0)|Z)=>[...f(R*R).flatMap(e=>f(T*T).flatMap(E=>f(U*U).map(d=>[e,E,d]))).find(([a,b,c])=>t(a,b)==P*P&&t(a,c)==Q*Q&&t(b,c)==S*S)]

Try it online!

Omits D, which is the origin.

The code assumes that D is the origin. There is an f function, defined as a default argument, which returns all representations of a positive integer as a sum of three squares of positive and/or negative integers. It then returns the first list of possible triplets of A, B and C coordinates, derived from calling f on the AD, BD and CD distances, that satisfy the distance requirements.

UPDATE: The code works on the first two testcases. The second one is shown in the TIO link above. Segmentation fault on the third one.

deleted 105 characters in body
Source Link
ophact
  • 3.2k
  • 1
  • 7
  • 24
Loading
added 135 characters in body
Source Link
ophact
  • 3.2k
  • 1
  • 7
  • 24
Loading
Source Link
ophact
  • 3.2k
  • 1
  • 7
  • 24
Loading